Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Change supported locales #359

Closed
Megidd opened this issue Oct 24, 2020 · 8 comments
Closed

Change supported locales #359

Megidd opened this issue Oct 24, 2020 · 8 comments

Comments

@Megidd
Copy link

Megidd commented Oct 24, 2020

I'm changing this line according to the relevant documentation by this patch:

           return MaterialApp(

             // ...

             initialRoute: initialRoute,
-            supportedLocales: GalleryLocalizations.supportedLocales,
+            supportedLocales: [
+              const Locale('en'),
+              const Locale('he'),
+            ],
             locale: GalleryOptions.of(context).locale,
             localeResolutionCallback: (locale, supportedLocales) {
               deviceLocale = locale;
               return locale;
             },

// ...

But the locales options on settings page are not modified. Any idea why?


I have a feeling like to change supported locales, I need to change l10n.yaml file. But I don't know what options are available. Can anybody help? Thanks!

@rami-a
Copy link
Contributor

rami-a commented Oct 26, 2020

The GalleryLocalizations.supportedLocales is used in settings.dart to populate the list in settings. So you'd have to make the change to GalleryLocalizations.supportedLocales instead to reduce the locales you want to support. Hope this answers your question!

@rami-a rami-a closed this as completed Oct 26, 2020
@Megidd
Copy link
Author

Megidd commented Oct 26, 2020

@rami-a The file .dart_tool/flutter_gen/gen_l10n/gallery_localizations.dart containing GalleryLocalizations class is not part of the repository. When I change the supportedLocales inside it, they keep coming back by automatic regeneration ☹️ Not sure what I'm missing.

@Megidd
Copy link
Author

Megidd commented Oct 26, 2020

I have studied this:

https://github.com/flutter/gallery/blob/master/lib/l10n/README.md

... and I'm still wondering how I can change supported locales permanently ... 😦

@rami-a
Copy link
Contributor

rami-a commented Oct 26, 2020

Interesting, @shihaohong could you take a look?

@rami-a rami-a reopened this Oct 26, 2020
@shihaohong
Copy link

@Megidd Could you further describe your use case? Do you only want a subset of GalleryLocalizations.supportedLocales to be used by the application? What you did above should work if you only want to use two supported locales in your app:

           return MaterialApp(

             // ...

             initialRoute: initialRoute,
-            supportedLocales: GalleryLocalizations.supportedLocales,
+            supportedLocales: [
+              const Locale('en'),
+              const Locale('he'),
+            ],
             locale: GalleryOptions.of(context).locale,
             localeResolutionCallback: (locale, supportedLocales) {
               deviceLocale = locale;
               return locale;
             },
// ...

@shihaohong
Copy link

shihaohong commented Oct 27, 2020

Actually, I took a look at settings.dart and one way to do resolve your issue is to also modify the list there:

    var supportedLocales =
        List<Locale>.from(GalleryLocalizations.supportedLocales);

to the custom list you want to use.

GalleryLocalizations.supportedLocales is a convenience getter that provides the entire list of locales that is generated by the l10n tool. It's not a necessity, but is helpful if you would just want to use every single locale you support in your app. You can do what you're already doing at MaterialApp.supportedLocales and replace the code wherever in the gallery that uses GalleryLocalizations.supportedLocales with your subset of locales you need.

@shihaohong
Copy link

I'll close the issue for now, but feel free to reopen it if I misunderstood something!

@Megidd
Copy link
Author

Megidd commented Oct 27, 2020

@shihaohong Thanks! 😃 I can confirm that supported locales of settings page are on file lib/pages/settings.dart and can be limited by modifying this line with this patch:

-    var supportedLocales =
-        List<Locale>.from(GalleryLocalizations.supportedLocales);
+    var supportedLocales = [
+      const Locale('en'),
+      const Locale('he'),
+    ];
     supportedLocales.removeWhere((locale) => locale == deviceLocale);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants