सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
i18next एक फ्लटर/डार्ट पैकेज है जो i18next मानक के आधार पर स्थानीयकरण प्रारूपण प्रदान करता है। यह अंतरराष्ट्रीयकरण के प्रारूपण पहलू पर केंद्रित है, जिसमें प्लेसहोल्डर और बहुवचन के साथ संरचित अनुवाद प्रबंधन संभव होता है। एक पूर्ण-फीचर आईएनआई (i18n) समाधान नहीं होने के बावजूद, यह प्लेटफॉर्म के बीच स्थिर टेक्स्ट प्रारूपण का समर्थन करता है। विकासकर्ताओं के लिए डिज़ाइन किया गया है जिन्हें मानकीकृत स्थानीयकरण पैटर्न की आवश्यकता होती है, यह मौजूदा कार्य प्रवाहों के साथ अच्छी तरह से एकीकृत होता है। पैकेज एंड्रॉइड, आईओएस, वेब, मैकओएस, विंडोज और लिनक्स के साथ संगत है।
उपयोग
प्लेसहोल्डर्स के साथ अनुवादित स्ट्रिंग्स को प्रारूपित करना
अनुवाद में बहुवचन रूपों का प्रबंधन
बहुभाषी एप्प सामग्री का समर्थन करना
i18next-आधारित बैकएंड प्रणालियों के साथ एकीकरण
गतिशील संदेश रेंडरिंग को सरल बनाना
मुख्य विशेषताएँ
i18next मानक अनुपालन
प्लेसहोल्डर और बहुवचन समर्थन
प्लेटफॉर्म के अनुकूलता
हल्का प्रारूपण इंजन
मौजूदा अनुवाद फ़ाइल्स के साथ आसान एकीकरण
इनके लिए उपयुक्त
संरचित स्थानीयकरण की आवश्यकता वाले ऐप्स
i18next के परिचित विकासकर्मी
बाहरी अनुवाद प्रबंधन का उपयोग करने वाले प्रोजेक्ट
प्लेटफॉर्म के बीच सुसंगत प्रारूपण की आवश्यकता वाली टीमें
फ्रंटएंड-केंद्रित अंतरराष्ट्रीयकरण
विचार योग्य बातें
पूर्ण i18n उपकरण शामिल नहीं है
बाहरी अनुवाद फ़ाइल प्रबंधन की आवश्यकता है
प्रारूपण के लिए सीमित, लोकेल लोड करने या परिवर्तन के लिए नहीं
जटिल i18n कार्यप्रवाह के लिए उपयुक्त नहीं
अनुवाद संसाधनों के सही सेटअप पर निर्भर करता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
i18next
This is an adaptation of i18next standard for Dart with support for Flutter localization techniques. This package is still a work in progress.
Mind that this is still a pre-1.0.0 so breaking changes may occur frequently.
[x] Support for variables
[x] Support for namespaces
[x] Support for context
[x] Support for simple plural forms (one or plural)
[x] Support for multiple plural forms (one, few, many, plural, ...)
[x] Plural and context fallbacks
[x] Locale and namespace fallbacks
[x] Get string or object tree
[x] Support for nesting
[x] Flutter's LocalizationsDelegate support
[x] Asset bundle localizations data source (retrieves from pubspec.yaml). See the example for more details.
[ ] Sprintf support
[ ] Resource caching
[ ] Custom post-processing
[ ] ~Retrieve resource files from server~ (won't do, see https://github.com/williamhjcho/i18next/issues/27)
Usage
Simples way to add the latest version is to run flutter pub add i18next
Or you can declare it directly into your pubspec.yaml file:
dependencies:i18next:^0.9.0# (or the latest version available)
To use it with flutter's LocalizationsDelegate you first create I18NextLocalizationDelegate and register it in your WidgetsApp (MaterialApp or CupertinoApp).
I18NextLocalizationDelegate(
locales: widget.locales,
// this data source is from where the delegate will retrieve the localizations from (namespaces Map)
dataSource: ...,
// optional extra options can be added here
options: I18NextOptions(...),
),
Then to access and use it, simply call
Widgetbuild(BuildContext context) {
// It finds the i18next instance on the widgets tree via `Localizations.of`I18Next.of(context).t(...);
...
}
But if you want to handle it yourself, then simply instantiate it:
I18Next(
locale,
// This store is from where i18next will attempt to retrieve the localizations from.
resourceStore: ...,
// Optional extra options can be added here
options: I18NextOptions(...)
);
{"key1":"{{text, uppercase}} just uppercased","key2":"The current date is {{now, datetime(format:dd/MM/yyyy)}}","key3":"Right now we are in {{now, datetime(format:MMM), uppercase}}."}
i18next.t('key1', arguments: { 'text': 'my text' }); // 'MY TEXT just uppercased'
i18next.t('key2', arguments: { 'now': DateTime.now() }); // 'The current date is 21/01/2020'
i18next.t('key3', arguments: { 'now': DateTime.now() }); // 'Right now we are in JAN.'
There are other usages and possibilities as well, this is just an example of what is defined by this format.
Namespaces: A namespace can be thought of as logical groupings of different sets of translations. In a given namespace you could have a set of languages, each with their own set of keys. They can also be understood as separate files.
For example:
common.json: Things that are reused everywhere, eg. Button labels 'save', 'cancel'
validation.json: All validation texts
glossary.json: Words we want to be reused consistently inside texts
// common.json{"myKey":"This key is in common"}// feature.json{"myKey":"This key is in my feature"}
i18next.t('common:myKey'); // 'This key is in common'
i18next.t('feature:myKey'); // 'This key is in my feature'
i18next.t('friend'); // 'A friend'
i18next.t('friend', count: 1); // 'A friend'// It fallbacks to `friend` since `friend_plural` is not present
i18next.t('friend', count: 2); // 'A friend'
i18next.t('friend', context: 'female'); // 'A girlfriend'// It fallbacks to `friend` since `friend_male` is not present
i18next.t('friend', context: 'male'); // 'A friend'
There is a way to also set the default namespace or a order of namespaces so a key knows where to start looking for the translation.