Coder Social home page Coder Social logo

No fallback? about i18n_extension HOT 5 CLOSED

JCKodel avatar JCKodel commented on July 18, 2024
No fallback?

from i18n_extension.

Comments (5)

marcglasberg avatar marcglasberg commented on July 18, 2024

It should fallback, yes. It should try, in order:

  1. The exact locale (for example, if the device is "pt_br" and it finds "pt_br").
  2. Then the general language (for example, if the device is "pt_br" and it finds "pt").
  3. Then any locale with that language (for example, if the device is "pt_br" and it finds "pt_ao").

But, at the moment, the locale in the constructor should not be general. Try Translations("pt_br") instead of Translations("pt").

In other words, try this:

static var t = Translations("pt_br") +
  {
  "pt_br": "ENTRAR COM GOOGLE",
  "en": "ENTER WITH GOOGLE",
  "es": "INICIA COM GOOGLE",
  };

If it doesn't work, please let me know.

But even if it works, you are right that it should accept Translations("pt"). In a future version I will change that. I just need Dart 2.6 to go to the stable channel so that I can work in this package again.

Also, have a look at https://github.com/marcglasberg/i18n_extension/blob/master/test/i18n_extension_test.dart and see that it tests the fallbacks. If you can, try to modify some of the tests there to create a failing test to help me fix the problem.

from i18n_extension.

JCKodel avatar JCKodel commented on July 18, 2024

Phone: English, United States

static var t = Translations("pt_br") +
    {
      "pt": "ENTRAR COM GOOGLE",
      "en": "ENTER WITH GOOGLE",
      "es": "INICIA COM GOOGLE",
    };

Error: `No default translation for 'pt_br'. But I don't want just br, I want all portuguese variants!

static var t = Translations("pt_br") +
    {
      "pt_br": "ENTRAR COM GOOGLE",
      "en": "ENTER WITH GOOGLE",
      "es": "INICIA COM GOOGLE",
    };

Button remains in portuguese (should be english).

Can't figure out how this plugin works =\

from i18n_extension.

marcglasberg avatar marcglasberg commented on July 18, 2024

Ok, no problem. Can you please provide me with some minimum runnable code (with main method and all) demonstrating the problem? I need to reproduce it to be able to fix it.

By the way, have you tried running the example? https://github.com/marcglasberg/i18n_extension/blob/master/example/lib/main.dart

from i18n_extension.

JCKodel avatar JCKodel commented on July 18, 2024

Working as this:

On main.dart:

return MaterialApp(
      debugShowCheckedModeBanner: false,
      navigatorKey: Catcher.navigatorKey,
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [Locale("pt"), Locale("en"), Locale("es")],
      localeResolutionCallback: (locale, locales) {
        print("FALLBACK TO ${locale.toLanguageTag()}");

        if (locale.languageCode == "pt") {
          return const Locale("pt", "BR");
        } else if (locale.languageCode == "en") {
          return const Locale("en");
        } else if (locale.languageCode == "es") {
          return const Locale("es");
        }

        return const Locale("en");
      },

(needed to fallback to pt-BR when language is pt-*, otherwise, it won't work)

Then, with this translations:

  static var t = Translations("pt_br") +
      {
        "pt_br": "ENTRAR COM GOOGLE",
        "en": "ENTER WITH GOOGLE",
        "es": "INICIA COM GOOGLE",
      };

Now it works as intended (with my phone set to English United State, it calls the fallback code, so I set it to "en" and it works).

from i18n_extension.

marcglasberg avatar marcglasberg commented on July 18, 2024

You must wrap your widgets with I18n(child: ...) and you don't seem to be doing that:

@override
Widget build(BuildContext context) {
 return MaterialApp(
   home: I18n(child: ...)
 );
}

from i18n_extension.

Related Issues (20)

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.