{"id":20507240,"url":"https://github.com/nombrekeff/klocalizations_flutter","last_synced_at":"2025-09-25T08:31:47.980Z","repository":{"id":40298531,"uuid":"405242846","full_name":"nombrekeff/klocalizations_flutter","owner":"nombrekeff","description":"Wrapper around flutter_localizations, adding some extra functionality","archived":false,"fork":false,"pushed_at":"2022-09-13T11:08:28.000Z","size":161,"stargazers_count":3,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-15T20:03:56.828Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/nombrekeff.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-11T00:11:49.000Z","updated_at":"2024-04-15T17:50:31.000Z","dependencies_parsed_at":"2022-07-29T00:19:10.837Z","dependency_job_id":null,"html_url":"https://github.com/nombrekeff/klocalizations_flutter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nombrekeff%2Fklocalizations_flutter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nombrekeff%2Fklocalizations_flutter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nombrekeff%2Fklocalizations_flutter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nombrekeff%2Fklocalizations_flutter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nombrekeff","download_url":"https://codeload.github.com/nombrekeff/klocalizations_flutter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234170677,"owners_count":18790525,"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":[],"created_at":"2024-11-15T20:04:12.315Z","updated_at":"2025-09-25T08:31:42.692Z","avatar_url":"https://github.com/nombrekeff.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KLocalizations\n\n[![Pub Version](https://img.shields.io/pub/v/klocalizations_flutter?style=flat-square)](https://pub.dev/packages/klocalizations_flutter)\n\nWrapper around [flutter_localizations](https://api.flutter.dev/flutter/flutter_localizations/flutter_localizations-library.html), adding some extra functionality and abstracting some of the common logic. \n\n## Features\n* **Easy setup**\n* **Parameter interpolation**\n* Access translations with **dot notation** (`home.title`)\n* Change locale from anywhere\n* `LocalizedText` widget\n\n## How to use\n\n### 1. Create translations files\nThe first this we need to do is to create the files containing our translations for each of the supported languages.\n\nBy default KLocalizations expects them to be located under `'assets/translations'`, but can be specified on setup. The configuration files must be in JSON format.\n\n**Example:**\n```json\n// assets/translations/es.json\n{\n  \"welcome\": \"Bienvenido a klocalizations demo!\",\n  \"home\": {\n    \"title\": \"KLocalizations demo!\",\n    \"counter\": \"Has clicado {{count}} veces\"\n  },\n}\n```\n\n\n### 2. Setup\n\n```dart\nvoid main() {\n  runApp(\n    KLocalizations.asChangeNotifier(\n      locale: supportedLocales[0],\n      defaultLocale: supportedLocales[0],\n      supportedLocales: supportedLocales,\n      localizationsAssetsPath: 'assets/translations',\n      child: MyApp(),\n    ),\n  );\n}\n\nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final localizations = KLocalizations.of(context);\n\n    return MaterialApp(\n      locale: localizations.locale,\n      supportedLocales: localizations.supportedLocales,\n      localizationsDelegates: [\n        localizations.delegate,\n        GlobalMaterialLocalizations.delegate,\n        GlobalCupertinoLocalizations.delegate,\n        GlobalWidgetsLocalizations.delegate\n      ],\n      home: MyApp(),\n    );\n  }\n}\n```\n\n#### 2.1. Add assets to pubspec\nThe path to the translation files assets must be declared in the `pubspec.yml` so that Flutter lets us access them:\n```yml\nflutter:\n  assets:\n    - assets/translations/\n```\n\n\u003e The asset path must be the same as the one passed in `localizationsAssetsPath`.\n\n### 3. Translating\n\nNow we are ready to start translating in the app. KLocalizations offers 2 ways of doing this, by using **KLocalizations.translate()** or using the **LocalizedText** widget.\n\n#### KLocalizations.translate()\n\nThis method receives a string (or key) and returns the translated string. This is how you would use it: \n\n```dart\n@override\nWidget build(BuildContext context) {\n  final localizations = KLocalizations.of(context);\n\n  return Column(\n    children: [\n      Text(localizations.translate('welcome')),\n      Text(localizations.translate('home.title')),\n      Text(localizations.translate('home.counter', { 'count': 12 })),\n    ]\n  );\n}\n```\n\n#### LocalizedText\n\n**KLocalizatons** offers a text widget that behaves exactly like Flutter's **Text** widget but tries to translate the given string using `KLocalizatons`. It also accepts params for interpolation. Used like this:\n\n```dart\n@override\nWidget build(BuildContext context) {\n  return Column(\n    children: [\n      LocalizedText('welcome'),\n      LocalizedText('home.title', selectable: true),\n      LocalizedText.selectable('home.counter', params: { 'count': 12 }),\n    ]\n  );\n}\n```\n\n\u003e `LocalizedText` accepts the same arguments as [Text](https://api.flutter.dev/flutter/widgets/Text-class.html) plus some additional parameters. You can find the complete documentation [here](https://pub.dev/documentation/klocalizations_flutter/latest/klocalizations_flutter/LocalizedText-class.html).\n\n\n### 4. Changing locale\n\nChanging locale is not a big deal, we just need to tell **KLocalizatons** to change it:\n```dart\nKLocalizations.of(context).setLocale(locale);\n```\n\nThis will rebuild the widget tree and apply the selected locale across the app.\n\n\n## Additional info\n\n* Complete example [here](https://github.com/nombrekeff/klocalizations_flutter/tree/main/example)\n* Docs can be found [here](https://pub.dev/documentation/klocalizations_flutter)\n\nIf you encounter any problems or fancy a feature to be added please head over to the GitHub [repository](https://github.com/nombrekeff/klocalizations_flutter/) and [drop an issue](https://github.com/nombrekeff/klocalizations_flutter/issues/new).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnombrekeff%2Fklocalizations_flutter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnombrekeff%2Fklocalizations_flutter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnombrekeff%2Fklocalizations_flutter/lists"}