पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv0.11.1

arb_utils

i18n/l10n/अनुवाद के साथ काम करने के लिए .arb फ़ाइलों के साथ काम करने के लिए उपकरणों का सेट (डार्ट का प्रिय तरीका)

AndroidiOSWebmacOSWindowsLinux
30-दिन डाउनलोड
12.6 हज़ार
लाइक
23
Pub अंक
140

पैकेज इंस्टॉल करें

flutter pub add arb_utils

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

एक उपयोगिताओं का संग्रह जो Flutter एप्लिकेशन में .arb फ़ाइलों के साथ काम करने को सुविधाजनक बनाने के लिए डिज़ाइन किया गया है, जिससे अंतरराष्ट्रीयकरण और स्थानीयकरण का प्रभावी प्रबंधन संभव होता है। यह पार्सिंग, वैधता और arb फ़ाइलों के रूपांतरण का समर्थन करता है, जिससे विभिन्न भाषाओं में अनुवाद बनाए रखना आसान हो जाता है। यह पैकेज Dart के i18n वर्कफ़्लो में बिना किसी बाधा के एकीकृत होता है और अनुवाद फ़ाइलों से संबंधित दोहराव वाले कार्यों को स्वचालित करके डेवलपर उत्पादकता को बढ़ाता है। यह बड़े पैमाने पर बहुभाषी ऐप्स के प्रबंधन करने वाली टीमों के लिए विशेष रूप से उपयोगी है।

उपयोग

  • Flutter ऐप्स में अनुवाद फ़ाइलों का प्रबंधन
  • ARB और अन्य प्रारूपों के बीच परिवर्तन करना
  • अनुवाद की जाँच करना
  • स्थानीयकरण कार्य प्रवाहों को स्वचालित करना
  • ARB फ़ाइलों से कोड उत्पन्न करना

मुख्य विशेषताएँ

  • ARB फ़ाइल पार्सिंग और सत्यापन को समर्थन करता है
  • ARB को JSON और अन्य प्रारूपों में बदलता है
  • फ्लटर के i18n सिस्टम के साथ एकीकृत
  • स्वचालन के लिए कमांड-लाइन इंटरफेस
  • सुनिश्चित करें कि की नामकरण और संरचना समान हो

इनके लिए उपयुक्त

  • स्थानीयकरण के लिए ARB का उपयोग करने वाले फ्लटर विकासकर्ता
  • कई भाषा अनुवाद प्रबंधित करने वाली टीमें
  • i18n के लिए CI/CD पाइपलाइन्स
  • स्वचालित अनुवाद संभालने की आवश्यकता वाले परियोजनाएँ

विचार योग्य बातें

  • ARB फ़ाइल प्रारूप के साथ परिचित होना आवश्यक है
  • ARB-आधारित वर्कफ़्लो के सीमित
  • CI एकीकरण के लिए अतिरिक्त सेटअप की आवश्यकता हो सकती है
  • एक पूर्ण i18n फ्रेमवर्क नहीं है लेकिन एक टूलसेट है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

arb_utils

Common actions to perform over .arb formatted strings

Usage

A simple usage example:

import 'package:arb_utils/arb_utils.dart';

main() {
  print('Generating .arb for translators...');
  var chkout = 'latestTranslationsProcessedBranch'; // or a49630b726c or HEAD^3 etc
  Process.runSync('git', 'checkout $chkout'.split(' '));
  var mainARBOld = File('lib/l10n/intl_en.arb').readAsStringSync();
  Process.runSync('git', 'checkout master'.split(' '));
  var mainARBNew = File('lib/l10n/intl_en.arb').readAsStringSync();
  File('lib/l10n/new_translations/intl_en.arb')
      .writeAsStringSync(sortARB(processNewKeys(mainARBNew, mainARBOld)));
  print('lib/l10n/new_translations/intl_en.arb generated');
}

Features

Manual language switching helpers

Normally there's the need of providing a way of manually changing the locale on runtime. Here is a super easy way of doing so depending on the state manager you use:
translation on runtime demo
The solution handles the persistance of the user selection for app restarts and so.

Provider/BLoC

Given that BLoC relies on Provider for working this solution will work easily for both state managers:

//make sure this line is written, your IDE may not add it automatically
import 'package:provider/provider.dart';
import 'package:arb_utils/state_managers/l10n_provider.dart';

//prefix your MaterialApp(//... with the following:
ChangeNotifierProvider(
      create: (_) => ProviderL10n(),
      child: Builder(builder: (context) {
        return MaterialApp(
          locale: context.watch<ProviderL10n>().locale,
          supportedLocales: AppLocalizations.supportedLocales,

//now add this widget wherever you want:
import 'package:arb_utils/arb_utils_flutter.dart';

LanguageSelectorDropdown(
  supportedLocales: AppLocalizations.supportedLocales,
  provider: context.read<ProviderL10n>(),
)
MobX/GetX/GetIt/Riverpod/Binder/Redux/etc

Pull Requests are always welcome :-D!

ArbClient

A way of getting your ARB translations dynamically, not hardcoded like S.of(context).key / AppLocalizations.of(context).key. It has been made with the pretension of supporting a way of getting the .arb files from the backend, on demand, but if it suits your use case, it just works. (PR are always welcome)

var arbClient = ArbClient(englishArbString, locale: 'en', onMissingKey: (key) => print('ARB key not found: $key'), exceptionOnMissingKey: kDebugMode, onMissingKeyValue: (key) => 'value of $key');
print(arbClient['hellowWorld']); // Hello World!
arbClient.reloadJson(json.decode(spanishArbString));
print(arbClient['hellowWorld']); // ¡Hola Mundo!
print(arbClient.get('helloName',{'name':'Nico'})); // ¡Hola Nico!
Standalone functions
sortARB

alters the order of every .arb key alphabetically, putting their @key metadata below every one

{
  "@aKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"simple description"
  },
  "aKey":"a simple key",
}

will be converted to:

{
  "aKey":"a simple key",
  "@aKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"simple description"
  }
}

You can also provide a custom sort function.

var arb1 = '''
{
    "clave":"valor",
    "@clave":{
        "description": "Descripcion"
    },
    "key":"value",
    "@key":{
        "description": "Description"
    }
}''';
var sortedArb1 = sortARB(arb1, (a, b) => a[1].compareTo(b[1]));
print(sortedArb1);
/*
{
    "key":"value",
    "@key":{
        "description": "Description"
    },
    "clave":"valor",
    "@clave":{
        "description": "Descripcion"
    }
}
*/

Know that the most common sortings are implemented out of the box with the following parameters

var sorted = sortARB(arbString, caseInsensitive: false, naturalOrdering: false, descendingOrdering: false);
diffARBs

Will generate a .arb formatted string with the keys that doesn't appear in both the provided .arb formatted arguments

var arb1 = '''
{
    "clave":"valor",
    "@clave":{
        "description": "Descripcion"
    },
    "key":"value",
    "@key":{
        "description": "Description"
    }
}''';
var arb2 = '''
{
    "clave":"valor",
    "@clave":{
        "description": "Descripcion"
    },
    "newKey":"new value",
    "@newKey":{
        "description": "new Description"
    }
}''';
var diffed = diffARBs(arb1, arb2);
print(diffed);
/*
{
    "key":"value",
    "@key":{
        "description": "Description"
    },
    "newKey":"new value",
    "@newKey":{
        "description": "new Description"
    }
}
*/
mergeARBs

Will include the latter .arb keys in the former one and output a .arb formatted string with the merged keys, privileging the latter ones

var former = '''{
  "aKey":"a simple key",
  "@aKey":{
    "description":"simple description"
  },
  "bKey":"a simple key",
  "@bKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"simple description"
  }
''';
var latter = '''{
  "aKey":"a MODIFIED simple key",
  "@aKey":{
    "description":"simple description"
  },
  "cKey":"a simple key",
  "@cKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"simple description"
  }
}''';
var merged = mergeARBs(former,latter);
print(merged);
/*
{
  "aKey":"a MODIFIED simple key",
  "@aKey":{
    "description":"simple description"
  },
  "bKey":"a simple key",
  "@bKey":{
    "description":"simple description"
  },
  "cKey":"a simple key",
  "@cKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"simple description"
  }
}
*/
processNewKeys

Compares an .arb formatted string with a previous version of itself and outputs a new .arb formatted string with the new keys found there (also the edited ones)

var oldVersion = '''{
  "aKey":"a simple key",
  "@aKey":{
    "description":"simple description"
  },
  "bKey":"a simple key",
  "@bKey":{
    "description":"simple description"
  },
  "cKey":"a simple key",
  "@cKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"simple description"
  }
}''';
var newVersion = '''{
  "aKey":"a MODIFIED simple key",
  "@aKey":{
    "description":"simple description"
  },
  "bKey":"a simple key",
  "@bKey":{
    "description":"simple description"
  },
  "cKey":"a simple key",
  "@cKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"A MORE ROBUST description"
  }
}''';
var newARB = processNewKeys(newVersion, oldVersion);
print(newARB);
/*
{
  "aKey":"a MODIFIED simple key",
  "@aKey":{
    "description":"simple description"
  },
  "zKey":"a simple key",
  "@zKey":{
    "description":"A MORE ROBUST description"
  }
}
*/

Bin scripts

Please run

dart pub global activate arb_utils

to enable arb_utils as an executable command on your system.

Sort

To easily sort an arb and update original file, use

arb_utils sort <INPUT FILE>

where <INPUT FILE> is a path to the input file.

Also, there are 3 flags for different sorting:

  • Case insensitive (--case-insensitive / -i): Whether to distinguish between lowercase and uppercase while ordering the keys.
  • Natural ordering (--natural-ordering / -n): Whether to take numbers as a single character and order them according to their numeric value (instead of ASCII one).
  • Descending (--descending / -d): Sort in descending order.

For example, to sort with case insensitive and in descending order, use:

arb_utils sort -i -d <INPUT FILE>
Add Entries

To programmatically add new entries to one or more arb files in one go, use

arb_utils add <key> --description '<description>' [locale:value...]

Example:

arb_utils add welcome --description 'Welcome message' en:'Welcome!' es:'¡Bienvenido!'

Or using a JSON template:

arb_utils add --json '{"welcome": "$VAL$", "@welcome": {"description": "Welcome message"}}' en:'Welcome!' es:'¡Bienvenido!'

The command will recursively find all .arb files in the current directory and its subdirectories by default. To specify specific files, use the --files (or -f) flag. New entries are added to the tail of the files by default. Use the --sort (or -s) flag to sort the files after adding. Note: The command will fail if values for all locales present in the .arb files are not provided.

List Keys

To list keys matching a regexp, use

arb_utils keys <regexp>

This will search in all .arb files found recursively by default. You can also specify files with --files flag.

Add Missing Default Metadata

To easily add missing metadata to an arb and update original file, use

arb_utils generate-meta <INPUT FILE>

where <INPUT FILE> is a path to the input file.

Reference

Check this article for understanding more about i18n with .arb in Flutter: https://phrase.com/blog/posts/flutter-localization/

श्रेणियाँ

निर्भरताएँ

निर्भरता सूची 6 आइटम

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट