Flutter Localization एक पैकेज है जिसका उपयोग मानचित्र डेटा के साथ ऐप में स्थानीयकरण के लिए किया जाता है। इसे अधिक आसान और तेजी से लागू करने के लिए बनाया गया है और flutter_localizations से प्रेरित है।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
Flutter Localization एक पैकेज है जिसका उद्देश्य नक्शे-आधारित डेटा का उपयोग करके ऐप में स्थानीयीकरण को सरल बनाना है। यह अंतर्राष्ट्रीयकरण के कार्यान्वयन को आसान बनाता है, जिससे फ्लटर ऐप्स में अनुवाद प्रबंधन तेजी से और आसानी से हो सकता है। आधिकारिक flutter_localizations पैकेज के आधार पर, यह एकाधिक भाषाओं और प्लेटफॉर्मों का समर्थन करता है, जिससे डेवलपर्स को Android, iOS, Web, macOS, Windows और Linux पर बहुभाषी अनुभव प्रदान करने में सक्षम होते हैं।
उपयोग
बहुभाषी ऐप समर्थन
आसान अनुवाद प्रबंधन
एप में भाषा परिवर्तन
क्रॉस-प्लेटफ़ॉर्म स्थानीयकरण
त्वरित i18n एकीकरण
डायनामिक भाषा अपडेट
मुख्य विशेषताएँ
नक्शे-आधारित अनुवाद संग्रह
हल्का और तेज़ सेटअप
flutter_localizations से प्रेरित
सभी प्रमुख प्लेटफॉर्म का समर्थन करता है
भाषा संचालन के लिए सरल API
एम्बेडेड फॉलबैक मैकेनिज्म
इनके लिए उपयुक्त
बहुभाषी एप्लिकेशन बनाने वाले डेवलपर्स
त्वरित i18n कार्यान्वयन की आवश्यकता वाली टीमें
गतिशील भाषा परिवर्तन की आवश्यकता वाले प्रोजेक्ट
वैश्विक दर्शकों के लिए लक्षित ऐप्स
त्वरित डेप्लॉयमेंट पर केंद्रित स्टार्टअप
अनुवाद प्रबंधित कर रहे फ्रंटएंड टीमें
विचार योग्य बातें
हाथ से मानचित्र डेटा सेटअप की आवश्यकता है
सीमित निर्मित अनुवाद उपकरण
बाहरी स्रोतों के साथ वास्तविक समय सिंक नहीं है
स्थिर या आधा-स्थिर सामग्री के लिए सबसे उपयुक्त
बड़े पैमाने पर अनुवाद कार्यप्रवाह के लिए अतिरिक्त उपकरण की आवश्यकता हो सकती है
बिल्कुल आई18एन समाधान बॉक्स के बाहर नहीं है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Flutter Localization
Flutter Localization is a package used for in-app localization with Map data or JSON assets. It is designed to
be easy and fast to implement. This package is inspired by the Flutter
SDK flutter_localizations
itself. Follow the steps below to use the package, or you can check out a
small example project of the package.
Breaking Changes
From version 0.3.0 onward, there is a major update that breaks the code in the initialize flow. Please re-check the
Project Configuration section to see more detail of migration from version 0.2 to 0.3. Don't worry, there
are only a few things to change and add.
How To Use
Prepare Language Source
From version 0.4.0 onward, we support 2 ways of language source (in-memory Map data and JSON asset file).
In-memory Map data: use more RAM but faster load time. Recommend for 3-5 languages support base on amount of
content you have in each Map data.
JSON Asset file: use less RAM but slightly slower than in-memory Map data. Recommend for more than 5 languages
support with large amount of content.
In-memory Map Data (Map<String, dynamic>)
Create a dart file which will contain all the Map data of the locale language your app need. You can change the file
name, class name, and file path whatever you like. Example:
mixinAppLocale {
staticconstString title = 'title';
staticconstMap<String, dynamic> EN = {title: 'Localization'};
staticconstMap<String, dynamic> KM = {title: 'ការធ្វើមូលដ្ឋានីយកម្ម'};
staticconstMap<String, dynamic> JA = {title: 'ローカリゼーション'};
}
Asset File (JSON assets)
You can also store your translations in JSON files and load them via assets. Asset's path is not restricted but the file
name is. You need to name the file follow your supported language code. For example, create assets/i18n/en.json:
Ensure plugin initialize. Update main function into async function, add WidgetsFlutterBinding.ensureInitialized()
and await FlutterLocalization.instance.ensureInitialized() before runApp() function like below.
Provide the list of MapLocale or JsonLocale and startup language for the app. This has to be done only at the
main.dart or the MaterialApp in your project.
@overridevoidinitState() {
super.initState();
localization.onTranslatedLanguage = _onTranslatedLanguage;
// Initialize with map-based_initializeLocalizationMapBased();
// or JSON asset base on your language source _initializeLocalizationJsonAsset();
// make sure to use only 1 type of source
}
// The setState call here is required to rebuild the app after language changes.void_onTranslatedLanguage(Locale? locale) {
setState(() {});
}
void_initializeLocalizationMapBased() {
localization.init(
initLanguageCode: 'en',
source: LocalizationSource.map,
mapLocales: const [
MapLocale('en', AppLocale.EN),
MapLocale('km', AppLocale.KM),
MapLocale('ja', AppLocale.JA),
],
);
}
void_initializeLocalizationJsonAsset() {
localization.init(
initLanguageCode: 'en',
source: LocalizationSource.jsonAsset,
jsonLocales: const [
JsonLocale('en', 'assets/i18n/en.json'),
JsonLocale('km', 'assets/i18n/km.json'),
JsonLocale('ja', 'assets/i18n/ja.json'),
],
);
}
Add supportedLocales and localizationsDelegates to the MaterialApp
To display the value from the Map data, just use the getString() extension by providing the context
(the AppLocale.title is the constant from mixin class above)
AppLocale.title.getString(context);
Extras
You also can get the language name too. If you don't specify the language code for the function, it will return the
language name depend on the current app locale
localization.getLanguageName(languageCode: 'en'); // English
localization.getLanguageName(languageCode: 'km'); // ភាសាខ្មែរ
localization.getLanguageName(languageCode: 'ja'); // 日本語
localization.getLanguageName(); // get language name depend on current app locale
If you need to use locale identifier in some case, you can get it from the current locale. The identifier format is
languageCode_scriptCode_countryCode. For scriptCode and countryCode are optional, this might return only
the languageCode.
localization.currentLocale.localeIdentifier;
Some Update Note
Version 0.4.0
Added support for loading translations from JSON assets using the new JsonLocale model.
Introduced LocalizationSource enum to choose between LocalizationSource.map and LocalizationSource.jsonAsset.
Version 0.3.0
From version 0.3.0 onward, there is a major update that breaks the code in the initialize flow. Please re-check the
README document at the beginning of the Project Configuration section to see more. The breaking change is related
to:
Update main() function from void to Future<void> async for package ensureInitialized function
Call ensureInitialized() function to init the core functionality of the package
Version 0.1.13
Added Strings Util and Context Extension for helping with localization text that are dynamic base on language.
Check the usage below or the example here.
As for Strings Util, it just formats string normally from the list of arguments to the full text string.
Strings.format('Hello %a, this is me %a.', ['Dara', 'Sopheak']);
// Result: Hello Dara, this is me Sopheak.
As for Context Extension, the full text and arguments you provide, will use to check and get data from the string
source. If the result is null, it will return the key that use to get the resource string.
context.formatString('This is %a package, version %a.', [AppLocale.title, 'LATEST'])
// Result: This is Localization package, version LATEST.
Version 0.1.11
You can provide the font family in the MapLocale model at the init() function that can be
from Assets or GoogleFonts
package.
// font family from assetMapLocale('en', AppLocale.EN, fontFamily: 'MuseoSans');
// or from GoogleFonts packageMapLocale('en', AppLocale.EN, fontFamily: GoogleFonts.lato().fontFamily);
Lastly, provide the font family to the MaterialApp's ThemeData