1

I am building a project that shows a company has 2 different stores. I want the app can click one store and then show the store strings using the same code as another store but shows different content. Or say, just switching the string table between two.

Now I have the directories: lib/l10n and lib/l10n_2 that contains the same file names, the same key names but different values. I found package intl can only generated class S but cannot switch the source. the localization directories

I have tried to modify intl package and used it locally but it shows forbidden.

Because every version of flutter_localizations from sdk depends on intl from hosted and my_project depends on intl from path, flutter_localizations from sdk is forbidden.
So, because predator_connect depends on flutter_localizations from sdk, version solving failed.

How can I do to the switching string table source?

timyau
  • 812
  • 1
  • 16
  • 27

1 Answers1

0

I found a solution that is:

  1. Manually generate 2 directories' .dart String files using gen-l10n:

Project1 and Project2 replace the below [project]

flutter gen-l10n --project-dir d:\temp\test_multi_proj 
--template-arb-file intl_en.arb
--arb-dir d:\temp\test_multi_proj\lib\l10n_[project]
--no-synthetic-package 
-output-dir d:\temp\test_multi_proj\lib\localizations\ 
--output-localization-file [project]_string.dart
--output-class [project]
  1. Create a file l10n.dart with class S and include both of these classes (Project1 & Project2). And class S should add S of() and S load() for get string and switch locale.
  2. Write a member variable to save current project and add a switchProject() function.
  3. In main.dart, import Project1 and Project2 class, add their delegate in
MaterialApp(
      locale: _locale,
      localizationsDelegates: [
Project1.delegate,
Project2.delegate,
]

The locale part please see another thread Reference.

That's it.

timyau
  • 812
  • 1
  • 16
  • 27