Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
MIT License
403 stars 118 forks source link

How to use flutter_translate in a package(plugin)? #37

Closed raindy29 closed 4 years ago

raindy29 commented 4 years ago

Can you give me an example, Other package is already used ?

bratan commented 4 years ago

You can use it the same way is used in an app. You initialize the delegate during the app startup as shown in https://github.com/bratan/flutter_translate/wiki/1.-Installation,-Configuration-&-Usage and then can use the translate or changeLocale method within the package.

raindy29 commented 4 years ago

I set the basepath of the package,But it affects the main() parameters

` void main() async { initializeReflectable(); // Imported from main.reflectable.dart

var delegate = await LocalizationDelegate.create( preferences: TranslatePreferences(), fallbackLocale: 'en_US', basePath: 'assets/i18n/', supportedLocales: ['en_US', 'zh_TW', 'ja_jp']);

runApp(LocalizedApp(delegate, App())); } `

my packages delegate = await LocalizationDelegate.create( preferences: TranslatePreferences(), fallbackLocale: localizationDelegate.currentLocale.toString(), basePath: 'packages/myproj/assets/i18n/', supportedLocales: ['en_US', 'zh_TW', 'ja_jp']);