Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
fix(translation): ignore invalid system locale
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Nov 13, 2021
1 parent 8aff163 commit 8dbddd1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
5 changes: 1 addition & 4 deletions lib/config/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ abstract class Config {
static const String repoAuthor = 'yukino-app';
static const String repoName = 'yukino';

// static const String storeURL =
// 'https://raw.githubusercontent.com/$repoAuthor/extensions-store/dist/extensions.json';

static const String storeURL =
'https://raw.githubusercontent.com/$repoAuthor/this-is-kek/main/store.json';
'https://raw.githubusercontent.com/$repoAuthor/extensions-store/dist/extensions.json';

static const String releasesURL =
'https://api.github.com/repos/$repoAuthor/$repoName/releases?per_page=20';
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/helpers/screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ abstract class Screen {
}
}

static Future<bool> isWakelockEnabled() => Wakelock.enabled;
static Future<bool> isWakelockEnabled() =>
!Platform.isLinux && Wakelock.enabled;

static Future<void> enableWakelock() async {
if (!Platform.isLinux) {
Expand Down
26 changes: 14 additions & 12 deletions lib/modules/translator/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ abstract class Translator {
static late TranslationSentences t;

static TranslationSentences? tryGetTranslation(final String _locale) {
final Locale locale = Locale.parse(_locale);

TranslationSentences? translation;
int threshold = 0;

for (final TranslationSentences x in translations) {
final int nThresh = x.locale.compare(locale);
if (nThresh > threshold) {
translation = x;
threshold = nThresh;
final Locale? locale = Locale.tryParse(_locale);

if (locale != null) {
TranslationSentences? translation;
int threshold = 0;

for (final TranslationSentences x in translations) {
final int nThresh = x.locale.compare(locale);
if (nThresh > threshold) {
translation = x;
threshold = nThresh;
}
}
}

return translation;
return translation;
}
}

static TranslationSentences getDefaultTranslation() =>
Expand Down
6 changes: 6 additions & 0 deletions packages/utilx/lib/utilities/locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Locale {
return Locale(lang, country);
}

static Locale? tryParse(final String locale) {
try {
return Locale.parse(locale);
} catch (_) {}
}

final LanguageCodes code;
final CountryCodes? country;

Expand Down

0 comments on commit 8dbddd1

Please sign in to comment.