-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[368] Add chinese traditional localization (#369)
* [368] feat: add chinese traditional localization and improve how localizations work * [368] docs: update pre-releases link in README.md
- Loading branch information
1 parent
3ed31df
commit 78456c0
Showing
9 changed files
with
101 additions
and
27 deletions.
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
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
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
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 @@ | ||
{} |
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 |
---|---|---|
@@ -1,29 +1,48 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import '../common/preferences/preference_key.dart'; | ||
import 'localizations_utils.dart'; | ||
|
||
/// Utilities for the application's locale. | ||
class LocaleUtils { | ||
/// Locale of the device. | ||
Locale get deviceLocale => Locale(Platform.localeName.split('_').first); | ||
Locale get deviceLocale { | ||
final localeCodes = Platform.localeName.split('-'); | ||
final languageCode = localeCodes.first; | ||
String? countryCode; | ||
if (localeCodes.length == 2) { | ||
countryCode = localeCodes[1]; | ||
} | ||
|
||
return Locale.fromSubtags(languageCode: languageCode, countryCode: countryCode); | ||
} | ||
|
||
/// Locale of the application. | ||
Locale get appLocale { | ||
final localePreferenceLanguageCode = PreferenceKey.locale.getPreferenceOrDefault(); | ||
final localeCodes = PreferenceKey.locale.getPreferenceOrDefault().split('-'); | ||
final languageCode = localeCodes.first; | ||
String? scriptCode; | ||
if (localeCodes.length == 2) { | ||
scriptCode = localeCodes[1]; | ||
} | ||
String? countryCode; | ||
if (localeCodes.length == 3) { | ||
countryCode = localeCodes[2]; | ||
} | ||
|
||
return Locale(localePreferenceLanguageCode); | ||
return Locale.fromSubtags(languageCode: languageCode, scriptCode: scriptCode, countryCode: countryCode); | ||
} | ||
|
||
/// Locale language code of the application. | ||
String get appLocaleLanguageCode => appLocale.languageCode; | ||
|
||
/// Sets the application's locale to [locale]. | ||
Future<void> setLocale(Locale locale) async { | ||
await PreferenceKey.locale.set(locale.languageCode); | ||
await PreferenceKey.locale.set(locale.toLanguageTag()); | ||
|
||
// Reset the hardcoded localizations. | ||
// Reset the hardcoded localizations | ||
await LocalizationsUtils().ensureInitialized(); | ||
} | ||
} |