-
Notifications
You must be signed in to change notification settings - Fork 549
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
Add localization #2748
Open
mosuem
wants to merge
20
commits into
main
Choose a base branch
from
addLocalization
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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
Add localization #2748
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c8fa740
Add english arb file
mosuem 4a41aba
Add Flutter localizations
mosuem f84ae43
Add test locale
mosuem ebd0586
Add localization example
mosuem 5d01ab4
Switch to template
mosuem 58aef90
Make final
mosuem 948bd91
Change deps
mosuem 4852c20
Regenerate
mosuem 3a8333c
Add readme
mosuem c52f6e3
Remove unsupported locales
mosuem ba05735
Fix readme
mosuem 3cc8300
Add button to change locale
mosuem fe95aa0
Add build verify
mosuem deea7c0
Remove toast
mosuem 58ba66b
Rev flutter_messages
mosuem 77cbabd
Merge branch 'main' into addLocalization
mosuem 3fa10c6
Fix
mosuem 4a6497a
Fix language selection
mosuem ba00e09
Add translations
mosuem dc42857
Update pkgs/sketch_pad/lib/l10n/en.g.dart
devoncarew File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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,11 @@ | ||
{ | ||
"@@locale": "de", | ||
"@@x-template": "en.arb", | ||
"newPad": "Neu", | ||
"samples": "Beispiele", | ||
"installSdk": "SDK installieren", | ||
"privacyNotice": "Datenschutzerklärung", | ||
"feedback": "Feedback", | ||
"channelSelection": "{channelName} channel", | ||
"switchedLocaleTo": "Zu {locale} gewechselt" | ||
} |
This file contains 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 @@ | ||
[0,"de","0O1C0hUg",0,null,[" channel",[0,0]],"Feedback","SDK installieren","Neu","Datenschutzerklärung","Beispiele",["Zu gewechselt",[3,0]]] |
This file contains 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,44 @@ | ||
{ | ||
"@@locale": "en", | ||
"newPad": "New", | ||
"@newPad": { | ||
"description": "Button to create a new pad" | ||
}, | ||
"samples": "Samples", | ||
"@samples": { | ||
"description": "Button to show a list of all samples" | ||
}, | ||
"installSdk": "Install SDK", | ||
"@installSdk": { | ||
"description": "Button to follow external link to webpage helping on installing the Dart SDK" | ||
}, | ||
"privacyNotice": "Privacy Notice", | ||
"@privacyNotice": { | ||
"description": "Button to show privacy notice on external web page" | ||
}, | ||
"feedback": "Feedback", | ||
"@feedback": { | ||
"description": "Button to give feedback on external web page" | ||
}, | ||
"channelSelection": "{channelName} channel", | ||
"@channelSelection": { | ||
"description": "Text field describing the Dart SDK channel selected by the user", | ||
"placeholders": { | ||
"channelName": { | ||
"type": "String", | ||
"description": "The name of the channel", | ||
"example": "Stable" | ||
} | ||
} | ||
}, | ||
"switchedLocaleTo": "Switched locale to {locale}", | ||
"@switchedLocaleTo": { | ||
"description": "Message toast to display after switching to a new locale", | ||
"placeholders": { | ||
"locale": { | ||
"type": "String", | ||
"description": "The displayname of the new locale." | ||
} | ||
} | ||
} | ||
} |
This file contains 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,48 @@ | ||
// Generated by package:messages_builder. | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:messages/package_intl_object.dart'; | ||
|
||
import 'en.g.dart'; | ||
|
||
class MessagesLocalizations { | ||
static Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates = [ | ||
delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
]; | ||
|
||
static LocalizationsDelegate<Messages> delegate = | ||
MessagesLocalizationsDelegate(); | ||
|
||
static List<Locale> get supportedLocales { | ||
return Messages.knownLocales.map((e) { | ||
final split = e.split('_'); | ||
final code = split.length > 1 ? split[1] : null; | ||
return Locale(split.first, code); | ||
}).toList(); | ||
} | ||
|
||
static Messages? of(BuildContext context) => | ||
Localizations.of<Messages>(context, Messages); | ||
} | ||
|
||
class MessagesLocalizationsDelegate extends LocalizationsDelegate<Messages> { | ||
mosuem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@override | ||
bool isSupported(Locale locale) => | ||
Messages.knownLocales.contains(locale.toString()); | ||
|
||
@override | ||
Future<Messages> load(Locale locale) async { | ||
await messages.loadLocale(locale.toString()); | ||
return messages; | ||
} | ||
|
||
@override | ||
bool shouldReload(LocalizationsDelegate<Messages> old) => false; | ||
} | ||
|
||
Messages messages = Messages(rootBundle.loadString, const OldIntlObject()); | ||
mosuem marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,69 @@ | ||
// Generated by package:messages_builder. | ||
|
||
import 'package:messages/messages_json.dart'; | ||
|
||
class Messages { | ||
Messages( | ||
this._fileLoader, | ||
this.intlObject, | ||
); | ||
|
||
final Future<String> Function(String id) _fileLoader; | ||
|
||
String _currentLocale = 'en'; | ||
|
||
final Map<String, MessageList> _messages = {}; | ||
|
||
static const carbs = { | ||
mosuem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'en': ('lib/l10n/en.json', '+6SmU+Pe'), | ||
'de': ('lib/l10n/de.json', '0O1C0hUg') | ||
}; | ||
|
||
IntlObject intlObject; | ||
|
||
String get currentLocale => _currentLocale; | ||
|
||
MessageList get _currentMessages => _messages[currentLocale]!; | ||
|
||
static Iterable<String> get knownLocales => carbs.keys; | ||
|
||
Future<void> loadLocale(String locale) async { | ||
if (!_messages.containsKey(locale)) { | ||
final info = carbs[locale]; | ||
final carb = info?.$1; | ||
if (carb == null) { | ||
throw ArgumentError('Locale $locale is not in $knownLocales'); | ||
} | ||
final data = await _fileLoader(carb); | ||
final messageList = MessageListJson.fromString(data, intlObject); | ||
if (messageList.preamble.hash != info?.$2) { | ||
throw ArgumentError(''' | ||
Messages file for locale $locale has different hash "${messageList.preamble.hash}" than generated code "${info?.$2}".'''); | ||
} | ||
_messages[locale] = messageList; | ||
} | ||
_currentLocale = locale; | ||
} | ||
|
||
void loadAllLocales() { | ||
for (final locale in knownLocales) { | ||
loadLocale(locale); | ||
} | ||
} | ||
|
||
String channelSelection(String channelName) => | ||
_currentMessages.generateStringAtIndex(0, [channelName]); | ||
|
||
String get feedback => _currentMessages.generateStringAtIndex(1, []); | ||
|
||
String get installSdk => _currentMessages.generateStringAtIndex(2, []); | ||
|
||
String get newPad => _currentMessages.generateStringAtIndex(3, []); | ||
|
||
String get privacyNotice => _currentMessages.generateStringAtIndex(4, []); | ||
|
||
String get samples => _currentMessages.generateStringAtIndex(5, []); | ||
|
||
String switchedLocaleTo(String locale) => | ||
_currentMessages.generateStringAtIndex(6, [locale]); | ||
} |
mosuem marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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 @@ | ||
[0,"en","+6SmU+Pe",0,null,[" channel",[0,0]],"Feedback","Install SDK","New","Privacy Notice","Samples",["Switched locale to ",[19,0]]] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be