-
-
Notifications
You must be signed in to change notification settings - Fork 109
Add localization (l10n/i18n) support with language selection #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dhruvi-16-me
wants to merge
2
commits into
AOSSIE-Org:dev
Choose a base branch
from
dhruvi-16-me:localization-foundation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| arb-dir: lib/l10n | ||
| template-arb-file: app_en.arb | ||
| output-localization-file: app_localizations.dart | ||
| output-class: AppLocalizations | ||
| output-dir: lib/l10n | ||
| nullable-getter: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| { | ||
| "@@locale": "en", | ||
| "appTitle": "Ell-ena", | ||
| "@appTitle": { | ||
| "description": "The application title shown in the task switcher and browser tab." | ||
| }, | ||
| "login": "Sign In", | ||
| "@login": { | ||
| "description": "Primary authentication action on the login screen." | ||
| }, | ||
| "signUp": "Sign Up", | ||
| "@signUp": { | ||
| "description": "Registration action on the authentication screens." | ||
| }, | ||
| "logout": "Logout", | ||
| "@logout": { | ||
| "description": "Logout action label." | ||
| }, | ||
| "logoutTitle": "Log out?", | ||
| "@logoutTitle": { | ||
| "description": "Title for the logout confirmation dialog." | ||
| }, | ||
| "logoutMessage": "You will need to log in again to access your account.", | ||
| "@logoutMessage": { | ||
| "description": "Body text for the logout confirmation dialog." | ||
| }, | ||
| "dashboard": "Dashboard", | ||
| "@dashboard": { | ||
| "description": "Dashboard navigation label." | ||
| }, | ||
| "tasks": "Tasks", | ||
| "@tasks": { | ||
| "description": "Tasks section label." | ||
| }, | ||
| "tickets": "Tickets", | ||
| "@tickets": { | ||
| "description": "Tickets section label." | ||
| }, | ||
| "meetings": "Meetings", | ||
| "@meetings": { | ||
| "description": "Meetings section label." | ||
| }, | ||
| "settings": "Settings", | ||
| "@settings": { | ||
| "description": "Settings section label." | ||
| }, | ||
| "cancel": "Cancel", | ||
| "@cancel": { | ||
| "description": "Generic cancel action." | ||
| }, | ||
| "save": "Save", | ||
| "@save": { | ||
| "description": "Generic save action." | ||
| }, | ||
| "loading": "Loading...", | ||
| "@loading": { | ||
| "description": "Generic loading indicator label." | ||
| }, | ||
| "search": "Search", | ||
| "@search": { | ||
| "description": "Generic search placeholder label." | ||
| }, | ||
| "language": "Language", | ||
| "@language": { | ||
| "description": "Language preference setting label." | ||
| }, | ||
| "languageName": "{localeCode, select, en{English} hi{हिन्दी} other{{localeCode}}}", | ||
| "@languageName": { | ||
| "description": "Display name for a language identified by locale code.", | ||
| "placeholders": { | ||
| "localeCode": { | ||
| "type": "String" | ||
| } | ||
| } | ||
| }, | ||
| "selectLanguage": "Select Language", | ||
| "@selectLanguage": { | ||
| "description": "Title for the language selection sheet." | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "@@locale": "hi", | ||
| "appTitle": "Ell-ena", | ||
| "login": "साइन इन", | ||
| "signUp": "साइन अप", | ||
| "logout": "लॉग आउट", | ||
| "logoutTitle": "लॉग आउट करें?", | ||
| "logoutMessage": "अपने खाते तक पहुँचने के लिए आपको दोबारा लॉग इन करना होगा।", | ||
| "dashboard": "डैशबोर्ड", | ||
| "tasks": "कार्य", | ||
| "tickets": "टिकट", | ||
| "meetings": "मीटिंग", | ||
| "settings": "सेटिंग्स", | ||
| "cancel": "रद्द करें", | ||
| "save": "सहेजें", | ||
| "loading": "लोड हो रहा है...", | ||
| "search": "खोजें", | ||
| "language": "भाषा", | ||
| "languageName": "{localeCode, select, en{अंग्रेज़ी} hi{हिन्दी} other{{localeCode}}}", | ||
| "selectLanguage": "भाषा चुनें" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
|
||
| import '../l10n/app_localizations.dart'; | ||
| import 'shared_preferences_provider.dart'; | ||
|
|
||
| part 'locale_provider.g.dart'; | ||
|
|
||
| const String _localeStorageKey = 'app_locale'; | ||
| const Locale _defaultLocale = Locale('en'); | ||
|
|
||
| /// Manages the active app [Locale] with SharedPreferences persistence. | ||
| @Riverpod(keepAlive: true) | ||
| class LocaleController extends _$LocaleController { | ||
| @override | ||
| Locale build() { | ||
| final prefs = ref.watch(sharedPreferencesProvider); | ||
| final code = prefs.getString(_localeStorageKey); | ||
| if (code != null && code.isNotEmpty) { | ||
| for (final locale in AppLocalizations.supportedLocales) { | ||
| if (locale.languageCode == code) { | ||
| return locale; | ||
| } | ||
| } | ||
| } | ||
| return _defaultLocale; | ||
| } | ||
|
|
||
| /// Updates locale and persists the language code. | ||
| Future<void> setLocale(Locale locale) async { | ||
| final prefs = ref.read(sharedPreferencesProvider); | ||
| await prefs.setString(_localeStorageKey, locale.languageCode); | ||
| state = locale; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:shared_preferences/shared_preferences.dart'; | ||
|
|
||
| /// SharedPreferences instance overridden at app startup. | ||
| final sharedPreferencesProvider = Provider<SharedPreferences>((ref) { | ||
| throw StateError( | ||
| 'sharedPreferencesProvider must be overridden in ProviderScope', | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.