Coder Social home page Coder Social logo

ilteoood / flutter_i18n Goto Github PK

View Code? Open in Web Editor NEW
214.0 214.0 57.0 1003 KB

I18n made easy, for Flutter!

License: MIT License

Dart 58.37% Objective-C 0.53% Ruby 2.79% Swift 1.78% HTML 1.39% Kotlin 1.14% Java 0.42% CMake 14.62% C++ 17.89% C 1.07%
dart flutter hacktoberfest i18n internationalization localization

flutter_i18n's Introduction

Hello World 👋

My name is Matteo, and I am a Senior Full Stack Developer from Italy 🇮🇹

In my profile, you can find:

  • 🔙 back-end projects made with Node, Go and a little bit of Python;
  • 🕸️ front-end projects made with React and vanilla JavaScript;
  • 📱 mobile libraries made with Flutter;
  • 👨‍💻 multi-architecture Docker images.

Everything here is made with ❤️

Do you like my work?

patreon or buy-me-a-coffee

Connect with me

linked-in medium telegram facebook instagram

My stats

Since October 24 2021, I've coded for Total time coded since Oct 24 2021

My GitHub stats Languages

Latest Medium posts

flutter_i18n's People

Contributors

adrian7123 avatar adrianfarkas avatar agordeev avatar allcontributors[bot] avatar amir-p avatar defint avatar dirkvranckaert avatar foldblade avatar ilteoood avatar j4nk3e avatar jlcool avatar juzi5201314 avatar lucasvienna avatar olequellec avatar pnghai avatar pumano avatar sjoulbak avatar tomk9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flutter_i18n's Issues

Translated array support

This new feature would bring the ability to return a translated array from the appropriate json file.
Here is an example:

"people": [
    {
        "name": "Paul",
        "surname": "Freeman"
    },
    {
        "name": "Charles",
        "surname": "Beckham"
    },
    {
        "name": "Lucy",
        "surname": "Rooney"
    }
]

This would be an example of a call to the array method.

FlutterI18n.array(buildContext, "people").map((person) {
    print('My name is ${person['name']} and my surname ${person['surname']}.');
});

And the output would be:

My name is Paul and my surname Freeman.
My name is Charles and my surname Beckham.
My name is Lucy and my surname Rooney.

Thanks :)

Feature request: Force locale on app start

Have an option to choose a locale (any - could be different from phones current locale) on app start.
I am not talking about a fallback locale but an app start locale.
Sometimes a users phone can be in English but I want my app to force a different locale.

This is possible with the built in localizations just by adding the "locale" field to the material app but it's not working with this package.

Another nice feature (not sure if possible) is if you could generate a map so that any translation field name would be easily found by the IDE instead of passing a string.
Something like: FlutterI18n.translate(context).hello instead of FlutterI18n.translate(context, 'hello')

Fallback for single translation

Hey ho,

thanks for providing that cool package.

I have currently two languages in my app.
Main language german and secondary english.

The english language file does miss some translations.

Is it possible to fall back to the "fallback-file" in the context of a single translation?

modify en.json,hot reload not update

modify en.json some key or value,click IDE 'hot reload',
and modify key are not update;

if add a key(example: title2) in en.json file,and click 'hot reload' button,console will print log:
flutter: title2 not found

how to modify json file support hot reload?

NoSuchMethodError:The method ‘[]’ was called on null.

I found that there were two things that would happen.

  1. Ios system, zh Chinese. An error will be reported after killing the process and restart the application to translate the first string.
  2. Occasionally. Problems can occur when switching to another page. And when you get back, the entire application will be in trouble.

Can it be solved in time?

NoSuchMethodError:The method ‘[]’ was called on null.
Receiver:null
Tried calling:[](“motto”)

bug in pubspec.yaml?

flutter:
uses-material-design: true
assets:

  • assets/flutter_i18n/

it show me error

E/flutter ( 6382): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Unable to load asset: assets/flutter_i18n/zh_Hans.json
E/flutter ( 6382): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)


flutter:
uses-material-design: true
assets:

  • assets/flutter_i18n/en_us.json
  • assets/flutter_i18n/zh_hans.json

this is work fine.

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17763.437], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.3)
[√] Connected device (1 available)

Unable to load asset

First of all, thanks for the great library!
I use yaml files and use code from example project. The error I get is:

FlutterError (Unable to load asset: assets/i18n/fr.json)

on line:

await flutterI18nDelegate.load(null);

The reason of this error is this function:

  Future<void> _loadFile(final String fileName) async {
    try {
      decodedMap = await rootBundle
          .loadString('$_basePath/$fileName.json')
          .then((jsonString) => json.decode(jsonString));
    } on FlutterError catch (_) {
      var yamlNode = await rootBundle
          .loadString('$_basePath/$fileName.yaml')
          .then((yamlString) => loadYamlNode(yamlString));
      decodedMap = _convertYaml(yamlNode);
    }
  }

For some reason debugger considers the exception as uncaught and therefore stops program. This is quite annoying.
I think a better solution is to let the user specify which file type he uses for translation.

Update intl dependency

When trying to update the intl dependency to the latest version, 0.15.8, flutter outputs this error message:

Because no versions of flutter_i18n match >0.6.3 <0.7.0 and flutter_i18n 0.6.3 depends on flutter_localizations any from sdk, flutter_i18n ^0.6.3 requires flutter_localizations any from sdk.

And because every version of flutter_localizations from sdk depends on intl 0.15.7, flutter_i18n ^0.6.3 requires intl 0.15.7.

So, because cherry depends on both flutter_i18n ^0.6.3 and intl ^0.15.8, version solving failed.

Add an option to load a default locale inside the main function

I'm not using country codes, but a language selector within my app.
When i restart the app, i now load the selected locale during initstate, and then use setstate to refresh the screen.
This causes both unnecessary file loading, and causes the default language to be visible for a second.
Preferably, i would set the default locale when creating an instance of FlutterI18nDelegate inside the main method.
I saw one of the (now closed) pull requests (#40 ) implemented this feature, but it unfortunately never got merged into master.

Getting keys from JSON file

Hi,

really great and helpful library, thanks for that.

Is there any way or you can implement, to expose keys from JSON file. So that we don't need to hardcode these in string parameter.

FlutterI18nDelegate is breaking tests

I'm trying to create a WidgetHelper class that will build the MaterialApp for every test. In this class I use the FlutterI18nDelegate:

class WidgetTestHelper {
  const WidgetTestHelper();

  MaterialApp generateApp(Widget body,) {
    return MaterialApp(
      theme: theme.light,
      localizationsDelegates: [
        FlutterI18nDelegate(
            useCountryCode: true, fallbackFile: 'en', path: 'lib/assets/i18n'),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      home: Scaffold(
        body: body,
      ),
    );
  }
}

If I try now to run these tests together:

void main() {
  testWidgets('Should find a FlatButton', (WidgetTester tester) async {
    WidgetTestHelper helper = WidgetTestHelper();

    await tester.pumpWidget(helper.generateApp(FlatButton()));
    await tester.pumpAndSettle();
    expect(find.byType(FlatButton), findsOneWidget);
  });
  testWidgets('Should find a RaisedButton', (WidgetTester tester) async {
    WidgetTestHelper helper = WidgetTestHelper();
    await tester.pumpWidget(helper.generateApp(RaisedButton()));
    await tester.pumpAndSettle();
    expect(find.byType(RaisedButton), findsOneWidget);
  });
}

they will fail while, if I test them one by one, they succeed. If now I remove the FlutterI18nDelegate and run again the tests together, they will succeed. Is it possible that this FlutterI18nDelegate creates some dependency between these tests?

How to localize a string variable

Hi, I'm new to flutter. I'm using this awesome project to localize my test app.
But I met a problem. How to localize a string variable?

class _HomePageState extends State<HomePage> {
  String hint= 'Tap 🌼 to start';
}

I can't use
String hint= FlutterI18n.translate(context, 'hint');

How to change default locale?

Hi ! I have a question . How to change the default locale?

In example :
localizationsDelegates: [
FlutterI18nDelegate(
useCountryCode: false, fallbackFile: 'es', path: 'assets/i18n'),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
]
I try to change the fallbackFile but the locale is always 'en'.

thanks for answer!

Plural translation

Hi, do you have plan to add plural translation function since it's a common requirement?
instead manually using if keyword every time.
So when you translate, you pass the plural count into the function.

(e.g. when you pass 1, it will return 'I have one apple.' when you pass 2 it will return 'I have two apples')

Thanks

Loading Other Language at App Start does not reflect in UI

I had this issue similar to #17. But it was solved based on your suggesetion in that thread.

This black screen issue happens when loading language at app start time. Any help please?

  final FlutterI18nDelegate flutterI18nDelegate = FlutterI18nDelegate(
      useCountryCode: false, fallbackFile: 'en', path: 'assets/i18n');

MaterialApp(
            title: 'Blouse Designs',
            theme: ThemeData(
              primarySwatch: Colors.pink,
            ),
            home: BlouseDesignApp(),
            localizationsDelegates: [
              flutterI18nDelegate,
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate
            ],
          );

And in the body, I use the below code to load the language on app start.

  void init() async{
    String userLanguage =
        PrefsProvider.prefs.getString("userLanguage") ?? "en";
    await FlutterI18n.refresh(context, Locale(userLanguage));
  }

  @override
  Future initState() {
    super.initState();

    init();
}

The app starts in default language and not in the chosen language. Once I go to different page and come back, language is changed.

Nice idea but the creator is a JERK

Keeps closing the issues instead of FIXING them.

  1. Still BLACK screen at start.
  2. The language doesn't UPDATE when you switch it more than 2 times and return to the app.

Fix `_findCurrentLocale()` (system locale mybe include scriptCode)

About #42 for chinese, system locale include scriptCode such as zh_Hans/zh_Hans_CN/zh_Hans_SG/zh_Hant_TW, so:

  Future<Locale> _findCurrentLocale() async {
    final String systemLocale = await findSystemLocale();
    final List<String> systemLocaleSplitted = systemLocale.split("_");
    return Future(
        () => Locale(systemLocaleSplitted[0], systemLocaleSplitted[1]));
  }

should to change as follows:

  Future<Locale> _findCurrentLocale() async {
    final String systemLocale = await findSystemLocale();
    final List<String> systemLocaleSplitted = systemLocale.split("_");
    return Future(() {
      String _countryCode;
      if (systemLocaleSplitted.length == 3) {
        // Hans, Hant, Latn, Arab or Cyrl
        _countryCode = systemLocaleSplitted[2];
      } else {
        // en_US, ru_RU, ar_AE, bo_IN and so on
        _countryCode = systemLocaleSplitted[1];
      }
      return Locale(systemLocaleSplitted[0], _countryCode);
    });
  }

Do you think so? See http://www.localeplanet.com/icu/ for language tag.

Debugging without Phones locale

Debugging will stop several times when starting, if the phones locale is not in the app.
The fallback is set and works as expected, it's just annoying to step through errors every time.

IDE: VSCode

Steps to reproduce:

  1. Make sure not to have the phones locale in your locales folder.
  2. Start debugging on the phone.

current locale is reset after hot reload

Hello!
I'm using this plugin for some time now. Recently I noticed, that after every hot reload my language falls back to the default english.
I reverted the version back to 5.2 with the necessary changes and there it works.

For some reason FlutterI18n.currentLocale(context) always returns en_US on the second call or something.

Can you have a look into it?

Thanks!

Cheers

Allow users to change base translations path

As the title says, it would be great if the base path for translations used an user-defined base path instead of a hard-coded value.

// in flutter_i18n.dart
static final String TRANSLATIONS_BASE_PATH;

// somewhere in `main.dart`
Flutteri18n.TRANSLATIONS_BASE_PATH = "assets/i18n";

Use SynchronousFuture to fix BlackSplashScreen?

Can you fix BlackSplashScreen(See issues #42) with the solution of Flutter i18n Plugin?

  @override
  Future<S> load(Locale locale) {
    final String lang = getLang(locale);
    if (lang != null) {
      switch (lang) {
        case "en":
          S.current = const $en();
          return SynchronousFuture<S>(S.current);
        case "zh_CN":
          S.current = const $zh_CN();
          return SynchronousFuture<S>(S.current);
        default:
        // NO-OP.
      }
    }
    S.current = const S();
    return SynchronousFuture<S>(S.current);
  }

Use SynchronousFuture to instead async and await, Change FlutterI18nDelegate like S.delegate

  @override
  Future<FlutterI18n> load(final Locale locale) async {
    if (FlutterI18nDelegate._currentTranslationObject == null ||
        FlutterI18nDelegate._currentTranslationObject.locale != locale) {
      FlutterI18nDelegate._currentTranslationObject =
          FlutterI18n(useCountryCode, fallbackFile, path);
      await FlutterI18nDelegate._currentTranslationObject.load();
    }
    return FlutterI18nDelegate._currentTranslationObject;
}

Flutter example issue

How to fix the warning on row 19 main.dart ?
msg: This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: MyApp.flutterI18nDelegatedart(must_be_immutable)

Flutter doctor:

    • Flutter version 1.12.13+hotfix.5 at /Users/mauro/Documents/SDK/flutter
    • Framework revision 27321ebbad (2 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0-rc2)
    • Android SDK at /Users/mauro/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.0-rc2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.41.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.7.1

[✓] Connected device (1 available)
    • iPad Pro (11-inch) • 271E614C-7A42-47BB-A95E-795BBDB20840 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3
      (simulator)

Translations are not updated when locale attribute in MaterialApp changes

As we have discussed a little bit here: #16 (comment)
the reason for this bug is that the translations are not chosen by the locale parameter inside the load method of the LocalizationsDelegate.

As reason why you don't do this you wrote:

The reason why I don't use the LocalizationsDelegate is to leave the possibility to override the fallback settings of the device (eg: English for everyone, even if the fallback language is Spanish).

However, the fallback language can be controlled by setting a custom localeResolutionCallback in the MaterialApp.
I think what you described could be implemented like this:

localeResolutionCallback: (preferredLocale, supportedLocales) {
    if (supportedLocales.contains(preferredLocale)) {
        return preferredLocale;
    }
    return supportedLocales.first;
},

Example:
If your supportedLocales are English and Spanish
supportedLocales: [Locale('en'), Locale('es')]
and your system locale preferences are:

  1. Italian
  2. Spanish
  3. English

then the callback would choose English, while without it Spanish would be chosen.

If the whole preference list is needed to choose the fallback manually, localeListResolutionCallback can be used.

As a second reason you gave:

Also, with this approch, the entire widget tree isn't reloaded when the system language change.

I believe this happens regardless.
https://flutter.dev/docs/development/accessibility-and-localization/internationalization
states that:

The Localizations widget defines the locale for its child and the localized resources that the child depends on. The WidgetsApp widget creates a Localizations widget and rebuilds it if the system’s locale changes.

And even if not, changing the language doesn't happen every second, so this wouldn't be a big deal.

So I propose the following changes:

  1. Remove FlutterI18n.refresh because intended way to control the language manually is via the locale attribute of MaterialApp.
  2. Remove the fallback in the FlutterI18nDelegate because you can control the fallback arbitrarily with localeResolutionCallback or localeListResolutionCallback.
  3. Choose the selected locale/language of FlutterI18n only by the locale in the load method of the FlutterI18nDelegate that creates the FlutterI18n object.

Side node:
Also I was wrong when I wrote

And when the locale is selected in this way, getting the current locale is really useful because I think the only alternative would be to create a custom Delegate that stores the locale somewhere when load is called.

Apparently Localizations.localeOf(context) can be used to get the currently selected locale. I guess this would make FlutterI18n.currentLocale redundant.

Second side note:
I think translating keys should be done with FlutterI18n.of(context).translate('key') not with FlutterI18n.translate(context, 'key') because it is more standard. But that's just preference... Maybe have both so that existing code doesn't break?

Language change to default when rotate screen/focus textfield/refresh ui

`
import 'package:flutter/material.dart';

import 'package:flutter_i18n/flutter_i18n.dart';

import 'package:flutter_i18n/flutter_i18n_delegate.dart';

import 'package:flutter_localizations/flutter_localizations.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
localizationsDelegates: [
FlutterI18nDelegate(false, 'en', 'assets/i18n'),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
);
}
}

class MyHomePage extends StatefulWidget {
@OverRide
MyHomeState createState() => new MyHomeState();
}

class MyHomeState extends State {
String currentLang = 'en';

int clicked = 0;

changeLanguage() {
setState(() {
currentLang = currentLang == 'en' ? 'it' : 'en';
});
}

incrementCounter() {
setState(() {
clicked++;
});
}

@OverRide
Widget build(BuildContext context) {
return new Scaffold(
appBar:
new AppBar(title: new Text(FlutterI18n.translate(context, "title"))),
body: new Builder(builder: (BuildContext context) {
return new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Text(FlutterI18n.translate(context, "label.main",
Map.fromIterables(["user"], ["Flutter lover"]))),
new Text(FlutterI18n.plural(context, "clicked.times", clicked)),
new FlatButton(
onPressed: () async {
incrementCounter();
},
child: new Text(
FlutterI18n.translate(context, "button.clickMe"))),
new FlatButton(
onPressed: () async {
changeLanguage();

                await FlutterI18n.refresh(context, currentLang);

                Scaffold.of(context).showSnackBar(new SnackBar(
                  content: new Text(
                      FlutterI18n.translate(context, "toastMessage")),
                ));
              },
              child: new Text(
                  FlutterI18n.translate(context, "button.clickMe")))
        ],
      ),
    );
  }),
);

}
}
`

Take this example. When I click the button to change the language to italian everything works fine. But if I rotate screen the language changes back to English.

Change language at runtime

Hi, is it possible to change app language at runtime?
(For example, there is language selection on my app settings)

Thanks

Error loading translation in v0.8.1

After the last update, the package isn't able to locate the translations file.
It works in version 0.8.0.

I/flutter ( 8175): Error loading translation Unable to load asset: assets/flutter_i18n/en.yaml
I/flutter ( 8175): Error loading translation fallback Unable to load asset: assets/flutter_i18n/en.yaml

It seems that it's trying to locate .yaml files by default, but I'm using .json instead.
Has something related to the default file extension changed?

Translation with multiple fields

At this moment a translation with multiple fields is not supported, for example:

String name = "Johnny";
String surname = "Appleseed";

FlutterI18n.translate(context, 'hello', name, surname);

In a JSON translation file:

en.json

{
    "hello": "Hello {0}, {1}.",
    "home": "I live in {0}, near {1}."
}

es.json

{
    "hello": "Hola {0}, {1}.",
    "home":  "Al lado de {1} vivo yo, en {0}."
}

The output is: "Hello Johnny, Appleseed", and "Hola Johnny, Appleseed".

The number in the translation string would indicate the index of the parameter in the function call itself.

This would we useful for the "home" example, since here, the spanish translation would pick the second parameter first, and then the first one.

Please, consider adding this :)
Thank you for your work, this packages is awesome!

Default Language

How to set default translations, for example, a phone has Korean lang on setting, but translations are only English and Russian in app?

Feature Request: disable/enable print if key is not found

Pretty cool library! Just a suggestion.
It would be good to enable/disable the warning showed when a key is not found: https://github.com/ilteoood/flutter_i18n/blob/master/lib/flutter_i18n.dart#L142

It could be an optional parameter that is set to true by default.

Even cooler, to set a Function<String> onKeyNotFound delegate, so we can decide if we want to print, show a dialog or just ignore it.

Is there any reason to not allow this and force the prints?

Can't make it work on iOS

Hi, I'm trying to use the package and it's working OK on Android. But in iOS simulator it only gets en_US locale. I've changed the settings to another languages but no lucky. Even deploying in Release Mode for my iOS device (in Portuguese) it still uses the en locale. Any hint on what should be done?

Here my Flutter Doctor:

[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.2 19C57, locale en-BR)
    • Flutter version 1.12.13+hotfix.5 at /Users/franklin/Development/flutter
    • Framework revision 27321ebbad (3 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/franklin/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (2 available)
    • iPhone do Franklin • 8ca28e9db21289c970d810c3625aa017c • ios • iOS 13.3
    • iPhone 11 Pro Max  • 29823942-BC97-4196-B74D-A03C680     • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

• No issues found!

And my main.dart

Future main() async {
  final FlutterI18nDelegate flutterI18nDelegate = FlutterI18nDelegate(
    useCountryCode: false, 
    fallbackFile: 'en',
    path: 'assets/flutter_i18n',
  );
  WidgetsFlutterBinding.ensureInitialized();
  await flutterI18nDelegate.load(null);
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((_) {
    runApp(new MyApp(flutterI18nDelegate));
  });
}

class MyApp extends StatelessWidget {
  FlutterI18nDelegate flutterI18nDelegate;

  MyApp(this.flutterI18nDelegate);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        appBarTheme: AppBarTheme(brightness: Brightness.light),
        primaryColor: Colors.white,
        scaffoldBackgroundColor: Colors.white,
        accentColor: kMainBlue,
        primaryTextTheme: TextTheme(
          title: TextStyle(
              fontFamily: 'Inter',
              fontWeight: FontWeight.w700,
              letterSpacing: 1.0),
        ),
      ),
      initialRoute: SplashScreen.id,
      routes: {
        LoginScreen.id: (context) => LoginScreen(),
        RegistrationScreen.id: (context) => RegistrationScreen(),
        HomeScreen.id: (context) => HomeScreen(),
        SplashScreen.id: (context) => SplashScreen(),
      },
      localizationsDelegates: [
        flutterI18nDelegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
    );
  }
}

Thanks!

workflow

Hi
I like the simplicity of your approach
Regarding the workflow, what tool do you use to detect missing translations?
Example if I have 10 big nested json language files and somewhere in es.json is missing translated string for some.key.nested.hello, how do you detect that?

Default language is always the same if I have two selected in device

Hi! Thanks for all your effort with this package! Unfortunately I'm having a problem in my tests with iOS platform. My supported locales in main are 'en' and 'pt' with this delegate: FlutterI18nDelegate(useCountryCode: false, path: 'assets/i18n', fallbackFile: 'en'). I have three situations in my tests:

  1. System with only one of those languages selected brings the correct language.
  2. System with another language selected brings the correct fallback language.
  3. System with English and Portuguese language selected always brings Portuguese. I wish I could bring the default system language, not the region.

Something I notice is that I keep getting a return of 'en_BR' (English as default) if I do print(FlutterI18n.currentLocale(context)); in situation 1, 'es_BR' (Spanish as default) if I'm in situation 2 and 'pt_BR' (English as default but Portuguese available) if I'm in situation 3.

Sorry if I'm doing something wrong, but I read the documentation and could not find anything that could help me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.