Skip to content

Commit

Permalink
add currency language, add chinese simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
emavgl committed Jan 26, 2024
1 parent f6fc6d6 commit 0074b9d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 157 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/res/xml/locales_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<locale android:name="ar"/>
<locale android:name="de"/>
<locale android:name="ru"/>
<locale android:name="zh-CN"/>
<locale android:name="pt-BR"/>
<locale android:name="pt-PT"/>
</locale-config>
144 changes: 0 additions & 144 deletions assets/locales/zh_TW.json

This file was deleted.

13 changes: 9 additions & 4 deletions lib/helpers/records-utility-functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ bool usesWesternArabicNumerals(Locale locale) {
return getCurrencyValueString(1234, locale: locale, turnOffGrouping: true).contains("1234");
}

Locale getCurrencyLocale() {
return ServiceConfig.currencyLocale!;
}

String getCurrencyValueString(double? value, { turnOffGrouping = false, locale}) {
if (value == null) return "";
NumberFormat numberFormat;
bool useGroupSeparator = ServiceConfig.sharedPreferences?.getBool("useGroupSeparator") ?? true;
int decimalDigits = ServiceConfig.sharedPreferences?.getInt("numDecimalDigits") ?? 2;
try {
if (locale == null) {
locale = I18n.locale;
locale = getCurrencyLocale();
}
numberFormat = new NumberFormat.currency(
locale: locale.toString(), symbol: "", decimalDigits: decimalDigits);
Expand All @@ -98,15 +102,16 @@ String getCurrencyValueString(double? value, { turnOffGrouping = false, locale})

double? tryParseCurrencyString(String toParse) {
try {
Locale myLocale = I18n.locale;
Intl.defaultLocale = myLocale.toString();
Locale myLocale = getCurrencyLocale();

// Intl.defaultLocale = myLocale.toString();
// Clean up from user defined grouping separator if they ever
// end up here
var userDefinedGroupingSeparator = getUserDefinedGroupingSeparator();
if (userDefinedGroupingSeparator != null) {
toParse = toParse.replaceAll(userDefinedGroupingSeparator, "");
}
num f = NumberFormat().parse(toParse);
num f = NumberFormat(null, myLocale.toString()).parse(toParse);
return f.toDouble();
} catch (e) {
return null;
Expand Down
19 changes: 11 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,9 @@ class OinkoinAppState extends State<OinkoinApp> {
// translations, but it will be used for the currency format

Locale attemptedLocale = locales![0];
Locale toSet = attemptedLocale;
if (usesWesternArabicNumerals(attemptedLocale)) {
toSet = attemptedLocale;
} else {
toSet = Locale.fromSubtags(languageCode: 'en', countryCode: "US");
}
setCurrencyLocale(attemptedLocale);

checkForSettingInconsistency(toSet);
return toSet;
return attemptedLocale;
},
supportedLocales: [
const Locale.fromSubtags(languageCode: 'en'),
Expand All @@ -86,6 +80,7 @@ class OinkoinAppState extends State<OinkoinApp> {
const Locale.fromSubtags(languageCode: 'es'),
const Locale.fromSubtags(languageCode: 'ar'),
const Locale.fromSubtags(languageCode: 'ru'),
const Locale.fromSubtags(languageCode: 'zh', countryCode: "CN"),
const Locale.fromSubtags(languageCode: 'pt', countryCode: "BR"),
const Locale.fromSubtags(languageCode: 'pt', countryCode: "PT")
],
Expand All @@ -112,6 +107,14 @@ class OinkoinAppState extends State<OinkoinApp> {
loadAsync = MyI18n.loadTranslations();
}

void setCurrencyLocale(Locale toSet) {
if (!usesWesternArabicNumerals(toSet)) {
toSet = Locale.fromSubtags(languageCode: 'en', countryCode: "US");
}
checkForSettingInconsistency(toSet);
ServiceConfig.currencyLocale = toSet;
}

void checkForSettingInconsistency(Locale toSet) {
// Custom Group Separator Inconsistency
bool userDefinedGroupingSeparator = ServiceConfig.sharedPreferences!.containsKey("groupSeparator");
Expand Down
3 changes: 3 additions & 0 deletions lib/services/service-config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:shared_preferences/shared_preferences.dart';

import 'database/database-interface.dart';
Expand All @@ -14,4 +16,5 @@ class ServiceConfig {

static String? packageName; // set in main.dart
static String? version; // set in main.dart
static Locale? currencyLocale; // set in main.dart
}
1 change: 0 additions & 1 deletion lib/statistics/category-summary-card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class CategorySummaryCard extends StatelessWidget {
),
), action: SnackBarAction(
label: 'Dismiss'.i18n,
textColor: Colors.yellow,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
Expand Down

0 comments on commit 0074b9d

Please sign in to comment.