{"id":15527695,"url":"https://github.com/kvs-coder/localized","last_synced_at":"2026-01-11T04:52:38.639Z","repository":{"id":53085006,"uuid":"304409903","full_name":"kvs-coder/localized","owner":"kvs-coder","description":"String extensions for different localizations and a translation utility to translate all your localized strings to desired languages without additional efforts.","archived":false,"fork":false,"pushed_at":"2021-11-13T20:41:51.000Z","size":169,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T23:41:11.819Z","etag":null,"topics":["dart","flutter","google","googletranslate","localization","localizations","microsoft","microsofttranslate","translation","yandex","yandextranslate"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/localized","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kvs-coder.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-15T18:06:47.000Z","updated_at":"2023-12-07T06:41:13.000Z","dependencies_parsed_at":"2022-09-09T19:11:16.912Z","dependency_job_id":null,"html_url":"https://github.com/kvs-coder/localized","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvs-coder%2Flocalized","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvs-coder%2Flocalized/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvs-coder%2Flocalized/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvs-coder%2Flocalized/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kvs-coder","download_url":"https://codeload.github.com/kvs-coder/localized/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250433321,"owners_count":21429851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","google","googletranslate","localization","localizations","microsoft","microsofttranslate","translation","yandex","yandextranslate"],"created_at":"2024-10-02T11:08:33.694Z","updated_at":"2026-01-11T04:52:38.600Z","avatar_url":"https://github.com/kvs-coder.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# localized\n\nString extensions for localization and a translation utility\n\n## Features\n- A script for creating your json localization files (see [Localization](#localization))\n- A **String** extension function _localized_\n- A translation utility (see [Translation](#translation))\n\n## Getting Started\n\n- Go inside pubspec.yaml file\n- Add this to your package's pubspec.yaml file: \n``` Dart\ndependencies:\n     localized: ^2.1.1\n```\n- Get dependencies\n\n``` shell\nflutter pub get\n``` \n\n## How to use\n\n### Localization\nThe package generates assets with i18n empty content as JSON files for future localized strings.\n\nFirst think about the localization you want to use and run the script (as an example EN, DE, RU are provided)\nspecifying the localizations in a line separated with commas\n\n``` shell\nflutter pub run localized:main -c -l en,de,ru\n``` \n\n(see list of [Parameters](#parameters))\n\nAs a result this will be added to the project tree:\n\n``` shell\n- assets\n    - i18n\n        - de.json\n        - en.json\n        - ru.json\n``` \n\nIn addition, you can specify the directory where the files\nwill be created\n\n``` shell\nflutter pub run localized:main -c -l en,de,ru -d res/localizations\n``` \n\n(see list of [Parameters](#parameters))\n\nFor now the result this will:\n\n``` shell\n- res\n    - localizations\n        - de.json\n        - en.json\n        - ru.json\n``` \n\nNext step is to add these assets in a \u003cb\u003epubspec.yaml\u003c/b\u003e file\n\n``` Dart\nflutter:\n  assets:\n    - assets/i18n/\n```\n\nOr your custom:\n\n``` Dart\nflutter:\n  assets:\n    - res/localizations/\n```\n\nThe algorithm will check if you have already created the localization files\nand will ask you if you want to overwrite them. If you select **Y** in the\ncommand line, the files and the content will be overwritten. In case of **N**\nnothing will change. If you enter other character the function will call itself\nrecursively until you provide a valid input.\n\nNext is to do some coding\n\n- Import the library \n``` Dart\nimport 'package:localized/localized.dart';\n```\n- Create a set of Locales\n``` Dart\n  final locales = [\n    Locale('de', 'DE'),\n    Locale('en', 'EN'),\n    Locale('ru', 'RU'),\n  ];\n```\n- In your \u003ci\u003eMateralApp\u003c/i\u003e widget set the created \u003ci\u003esupportedLocales\u003c/i\u003e with the created set\n``` Dart\n    supportedLocales: locales,\n```\n- In your \u003ci\u003eMateralApp\u003c/i\u003e widget set the list of \u003ci\u003elocalizationsDelegates\u003c/i\u003e \n``` Dart\n    localizationsDelegates: [\n      LocalizationService.delegate(locales),\n    ],\n```\n\nResult:\n\n``` Dart\nclass MyApp extends StatelessWidget {\n  final locales = [\n    // TODO: add new lang in array\n    Locale('de', 'DE'),\n    Locale('en', 'EN'),\n    Locale('ru', 'RU'),\n  ];\n\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      title: 'Flutter Demo',\n      supportedLocales: locales,\n      localizationsDelegates: [\n        GlobalCupertinoLocalizations.delegate,\n        GlobalMaterialLocalizations.delegate,\n        LocalizationService.delegate(locales: locales),\n      ],\n      theme: ThemeData(\n        primarySwatch: Colors.blue,\n        visualDensity: VisualDensity.adaptivePlatformDensity,\n      ),\n      home: MyHomePage(),\n    );\n  }\n}\n```\n\nThe settings finished, next is to try to localise strings.\n``` Dart\n    appBar: AppBar(\n      title: Text('title'.localized(context)), // Home page (en), Startseite (de), Домашняя страница (ru)\n    ),\n```\n\nDepending on the localization currently installed on the phone or the simulator, the appropriate value for the string will be called.\nFor instance if the current localization is en-EN, then \u003cb\u003een.json\u003c/b\u003e file will be used.\n\nHere is the full example\n\n``` Dart\nimport 'package:flutter/cupertino.dart';\nimport 'package:flutter/material.dart';\nimport 'package:localized/localized.dart';\n\nvoid main() {\n  runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n  final locales = [\n    // TODO: add new lang in array\n    Locale('de', 'DE'),\n    Locale('en', 'EN'),\n    Locale('ru', 'RU'),\n  ];\n\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      title: 'Flutter Demo',\n      supportedLocales: locales,\n      localizationsDelegates: [\n        LocalizationService.delegate(locales: locales),\n      ],\n      theme: ThemeData(\n        primarySwatch: Colors.blue,\n        visualDensity: VisualDensity.adaptivePlatformDensity,\n      ),\n      home: MyHomePage(),\n    );\n  }\n}\n\nclass MyHomePage extends StatefulWidget {\n  MyHomePage({Key key}) : super(key: key);\n\n  @override\n  _MyHomePageState createState() =\u003e _MyHomePageState();\n}\n\nclass _MyHomePageState extends State\u003cMyHomePage\u003e {\n  int _counter = 0;\n\n  void _incrementCounter() {\n    setState(() {\n      _counter++;\n    });\n  }\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        title: Text('title'.localized(context)),\n      ),\n      body: Center(\n        child: Column(\n          mainAxisAlignment: MainAxisAlignment.center,\n          children: \u003cWidget\u003e[\n            Text(\n              'amount_of_clicks'.localized(context),\n            ),\n            Text(\n              '$_counter',\n              style: Theme.of(context).textTheme.headline4,\n            ),\n          ],\n        ),\n      ),\n      floatingActionButton: FloatingActionButton(\n        onPressed: _incrementCounter,\n        tooltip: 'increase'.localized(context),\n        child: Icon(Icons.add),\n      ), // This trailing comma makes auto-formatting nicer for build methods.\n    );\n  }\n}\n```\n\n### Translation\n\nThis library supports translation of every string in your localized json files.\nThe APIs:\n- Google Cloud Translator\n- Yandex Translator\n- Microsoft Translator\n\nWhen you have created your json files, you may want to translate all your strings to desired languages.\n\nThe translation utility will check for existing keys in json files and if there is no translation for that key\nthe utility will handle this.\n\nFor Google:\n\n``` shell\nflutter pub run localized:main -t -l ru,en,de -p Google -k YOUR_GOOGLE_API_KEY -n MAXIMUM_BUFFER_NUMBER \n```\n\nFor Yandex:\n\n``` shell\nflutter pub run localized:main -t -l ru,en,de -p Yandex -f YOUR_YANDEX_FOLDER_ID -n MAXIMUM_BUFFER_NUMBER -i YOUR_YANDEX_IAM_TOKEN\n```\n\nFor Microsoft:\n\n``` shell\nflutter pub run localized:main -t -l ru,en,de -p Microsoft -m YOUR_MICROSOFT_KEY -r YOUR_REGION -n 100\n```\n\n(see list of [Parameters](#parameters))\n\nThe algorithm checks the amount of localization files you have and requires at least two of them.\nIt compares the amount of key-value pairs in several JSON files and lets translation\nrunning for those JSON files, which don't have the actual translated key-value pairs. It will not\noverwrite the already existing translation.\n\nPlease pay attention to MAXIMUM_BUFFER_NUMBER parameter. This parameter shows how many strings are allowed to be translated in one request.\nBy default, the parameter value is set to 1 and generally it will take much longer time for the translation.\n\nThe known limits are:\n- Google: 25 strings limit\n- Yandex: 100 string limit\n- Microsoft: 100 string limit\n\n#### Parameters\n\nGeneral:\n\n- **-c** Create sample localization files\n- **-t** Translate localization files\n- **-l** Language codes\n- **-d** i18n files directory. (\"assets/i18n\" by default)\n- **-p** Provider of translation API\n- **-n** The number of strings to translate in one request (\"1\" by default)\n\nGoogle **only**:\n\n- **-k** Google Project API key\n\nYandex **only**:\n\n- **-f** Yandex Folder ID\n- **-i** Yandex IAM token\n\nMicrosoft **only**:\n\n- **-m** Microsoft key\n- **-e** Microsoft endpoint. (\"https://api.cognitive.microsofttranslator.com/\" by default)\n- **-r** Microsoft multi-service or regional translator resource. It is required when using a multi-service subscription key.\n\n## License\nUnder \u003ca href=https://github.com/VictorKachalov/localized/blob/master/LICENSE\u003eMIT License\u003c/a\u003e\n\n## Sponsorhip\nIf you think that my repo helped you to solve the issues you struggle with, please don't be shy and sponsor :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkvs-coder%2Flocalized","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkvs-coder%2Flocalized","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkvs-coder%2Flocalized/lists"}