multilingual 1.1.5 copy "multilingual: ^1.1.5" to clipboard
multilingual: ^1.1.5 copied to clipboard

Plug-in for multilingual settings in apps.

Multilingual #

Multilingual is a powerful Flutter localization plugin that simplifies managing multiple languages in your app. It allows dynamic text translation, runtime language switching, and text replacement.

Buy Me a Coffee

Features #

  • Dynamic Translation: Use .trans() to easily translate text based on the current locale.
  • Custom Text Replacement: Replace specific text dynamically using .trans({'key': 'value'});.
  • Key Existence Check: Verify if a specific key exists with context.isTrans('key');.
  • Support for Multiple Languages: Seamlessly manage translations for multiple locales.

Usage #

Basic Setup #

Wrap your app with the Multilingual widget and define the supported languages:

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  Widget build(BuildContext context) {
    return Multilingual(
            languages: {
              Locale('ko', 'KR'): {'lan': '한국어', 'text_button': '언어변경'},
              Locale('en', 'US'): {'lan': 'English', 'text_button': 'Language change'},
              Locale('ja', 'JP'): {'lan': '日本語', 'text_button': '言語変更'},
            },
            builder: (context) {
              return MaterialApp(
                localizationsDelegates: MultilingualController.localizationsDelegates,
                supportedLocales: MultilingualController.supportedLocales,
                locale: MultilingualController.locale,
                home: Scaffold(
                  appBar: AppBar(
                    title: const Text('Plugin example app'),
                  ),
                  body: Center(
                    child: Column(
                      children: [
                        Text('lan'.trans()),
                        TextButton(onPressed: () {
                          Locale? locale = MultilingualController.locale;
                          Locale loc;
                          if (locale.toString() == 'ko_KR') {
                            loc = const Locale('en', 'US');
                          } else if (locale.toString() == 'en_US') {
                            loc = const Locale('ja', 'JP');
                          } else {
                            loc = const Locale('ko', 'KR');
                          }
                          MultilingualController.setLocale(loc);
                        }, child: Text('text_button'.trans())),
                      ],
                    ),
                  ),
                ),
              );
            }
    );
  }
}

Creating Your App #

Pass the MultilingualController to your app and use .trans() for translations:

Checking Key Existence #

Use context.isTrans('key') to check if a translation key exists:

if (context.isTrans('key')) {
  print('Translation key exists!');
} else {
  print('Translation key does not exist.');
}

Custom Text Replacement #

Replace specific text dynamically:

Text('Original text'.trans({'Original text': 'Replaced text'}));

Example Output #

  • Default Language: Korean (ko_KR)
    • Button Text: 언어변경
  • Switch to English (en_US)
    • Button Text: Language change
  • Switch to Japanese (ja_JP)
    • Button Text: 言語変更

Contributing #

Feel free to contribute to Multilingual by submitting issues or pull requests on the repository.

License #

This project is licensed under the MIT License.

3
likes
0
points
54
downloads

Publisher

unverified uploader

Weekly Downloads

Plug-in for multilingual settings in apps.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_localizations, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on multilingual