aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-09-27 21:54:39 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-09-27 21:54:39 -0700
commit236b10503612706ed914678d942ac604f2973f47 (patch)
treee557381dbdc721002346a0fc64b1a679280fa3f1 /modern/src/common
parent96af05dbf2171c4e194cf67c3c93d134ef467e50 (diff)
downloadtrackermap-web-236b10503612706ed914678d942ac604f2973f47.tar.gz
trackermap-web-236b10503612706ed914678d942ac604f2973f47.tar.bz2
trackermap-web-236b10503612706ed914678d942ac604f2973f47.zip
Implement notification settings
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/formatter.js23
-rw-r--r--modern/src/common/localization.js128
-rw-r--r--modern/src/common/stringUtils.js7
3 files changed, 86 insertions, 72 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js
index 8ad87e70..29108cec 100644
--- a/modern/src/common/formatter.js
+++ b/modern/src/common/formatter.js
@@ -1,7 +1,10 @@
import moment from 'moment';
import t from '../common/localization';
-const formatValue = (key, value) => {
+export const formatPosition = (key, value) => {
+ if (value != null && typeof value == 'object') {
+ value = value[key];
+ }
switch (key) {
case 'fixTime':
return moment(value).format('LLL');
@@ -15,19 +18,19 @@ const formatValue = (key, value) => {
return value + '%';
default:
if (typeof value === 'number') {
- return Number(value.toFixed(1));
+ return formatNumber(value);
} else if (typeof value === 'boolean') {
- return value ? t('sharedYes') : t('sharedNo');
+ return formatBoolean(value);
} else {
return value;
}
}
}
-export default (object, key) => {
- if (object != null && typeof object == 'object') {
- return formatValue(key, object[key]);
- } else {
- return formatValue(key, object);
- }
-};
+export const formatBoolean = (value) => {
+ return value ? t('sharedYes') : t('sharedNo');
+}
+
+export const formatNumber = (value, precision = 1) => {
+ return Number(value.toFixed(precision));
+}
diff --git a/modern/src/common/localization.js b/modern/src/common/localization.js
index 4c25697d..0a21a896 100644
--- a/modern/src/common/localization.js
+++ b/modern/src/common/localization.js
@@ -53,59 +53,59 @@ import zh from '../../../web/l10n/zh.json';
import zh_TW from '../../../web/l10n/zh_TW.json';
const supportedLanguages = {
- 'af': { data: af, name: 'Afrikaans' },
- 'ar': { data: ar, name: 'العربية' },
- 'az': { data: az, name: 'Azərbaycanca' },
- 'bg': { data: bg, name: 'Български' },
- 'bn': { data: bn, name: 'বাংলা' },
- 'cs': { data: cs, name: 'Čeština' },
- 'de': { data: de, name: 'Deutsch' },
- 'da': { data: da, name: 'Dansk' },
- 'el': { data: el, name: 'Ελληνικά' },
- 'en': { data: en, name: 'English' },
- 'es': { data: es, name: 'Español' },
- 'fa': { data: fa, name: 'فارسی' },
- 'fi': { data: fi, name: 'Suomi' },
- 'fr': { data: fr, name: 'Français' },
- 'he': { data: he, name: 'עברית' },
- 'hi': { data: hi, name: 'हिन्दी' },
- 'hr': { data: hr, name: 'Hrvatski' },
- 'hu': { data: hu, name: 'Magyar' },
- 'id': { data: id, name: 'Bahasa Indonesia' },
- 'it': { data: it, name: 'Italiano' },
- 'ja': { data: ja, name: '日本語' },
- 'ka': { data: ka, name: 'ქართული' },
- 'kk': { data: kk, name: 'Қазақша' },
- 'ko': { data: ko, name: '한국어' },
- 'km': { data: km, name: 'ភាសាខ្មែរ' },
- 'lo': { data: lo, name: 'ລາວ' },
- 'lt': { data: lt, name: 'Lietuvių' },
- 'lv': { data: lv, name: 'Latviešu' },
- 'ml': { data: ml, name: 'മലയാളം' },
- 'ms': { data: ms, name: 'بهاس ملايو' },
- 'nb': { data: nb, name: 'Norsk bokmål' },
- 'ne': { data: ne, name: 'नेपाली' },
- 'nl': { data: nl, name: 'Nederlands' },
- 'nn': { data: nn, name: 'Norsk nynorsk' },
- 'pl': { data: pl, name: 'Polski' },
- 'pt': { data: pt, name: 'Português' },
- 'pt_BR': { data: pt_BR, name: 'Português (Brasil)' },
- 'ro': { data: ro, name: 'Română' },
- 'ru': { data: ru, name: 'Русский' },
- 'si': { data: si, name: 'සිංහල' },
- 'sk': { data: sk, name: 'Slovenčina' },
- 'sl': { data: sl, name: 'Slovenščina' },
- 'sq': { data: sq, name: 'Shqipëria' },
- 'sr': { data: sr, name: 'Srpski' },
- 'sv': { data: sv, name: 'Svenska' },
- 'ta': { data: ta, name: 'தமிழ்' },
- 'th': { data: th, name: 'ไทย' },
- 'tr': { data: tr, name: 'Türkçe' },
- 'uk': { data: uk, name: 'Українська' },
- 'uz': { data: uz, name: 'Oʻzbekcha' },
- 'vi': { data: vi, name: 'Tiếng Việt' },
- 'zh': { data: zh, name: '中文' },
- 'zh_TW': { data: zh_TW, name: '中文 (Taiwan)' }
+ 'af': { data: af, name: 'Afrikaans' },
+ 'ar': { data: ar, name: 'العربية' },
+ 'az': { data: az, name: 'Azərbaycanca' },
+ 'bg': { data: bg, name: 'Български' },
+ 'bn': { data: bn, name: 'বাংলা' },
+ 'cs': { data: cs, name: 'Čeština' },
+ 'de': { data: de, name: 'Deutsch' },
+ 'da': { data: da, name: 'Dansk' },
+ 'el': { data: el, name: 'Ελληνικά' },
+ 'en': { data: en, name: 'English' },
+ 'es': { data: es, name: 'Español' },
+ 'fa': { data: fa, name: 'فارسی' },
+ 'fi': { data: fi, name: 'Suomi' },
+ 'fr': { data: fr, name: 'Français' },
+ 'he': { data: he, name: 'עברית' },
+ 'hi': { data: hi, name: 'हिन्दी' },
+ 'hr': { data: hr, name: 'Hrvatski' },
+ 'hu': { data: hu, name: 'Magyar' },
+ 'id': { data: id, name: 'Bahasa Indonesia' },
+ 'it': { data: it, name: 'Italiano' },
+ 'ja': { data: ja, name: '日本語' },
+ 'ka': { data: ka, name: 'ქართული' },
+ 'kk': { data: kk, name: 'Қазақша' },
+ 'ko': { data: ko, name: '한국어' },
+ 'km': { data: km, name: 'ភាសាខ្មែរ' },
+ 'lo': { data: lo, name: 'ລາວ' },
+ 'lt': { data: lt, name: 'Lietuvių' },
+ 'lv': { data: lv, name: 'Latviešu' },
+ 'ml': { data: ml, name: 'മലയാളം' },
+ 'ms': { data: ms, name: 'بهاس ملايو' },
+ 'nb': { data: nb, name: 'Norsk bokmål' },
+ 'ne': { data: ne, name: 'नेपाली' },
+ 'nl': { data: nl, name: 'Nederlands' },
+ 'nn': { data: nn, name: 'Norsk nynorsk' },
+ 'pl': { data: pl, name: 'Polski' },
+ 'pt': { data: pt, name: 'Português' },
+ 'pt_BR': { data: pt_BR, name: 'Português (Brasil)' },
+ 'ro': { data: ro, name: 'Română' },
+ 'ru': { data: ru, name: 'Русский' },
+ 'si': { data: si, name: 'සිංහල' },
+ 'sk': { data: sk, name: 'Slovenčina' },
+ 'sl': { data: sl, name: 'Slovenščina' },
+ 'sq': { data: sq, name: 'Shqipëria' },
+ 'sr': { data: sr, name: 'Srpski' },
+ 'sv': { data: sv, name: 'Svenska' },
+ 'ta': { data: ta, name: 'தமிழ்' },
+ 'th': { data: th, name: 'ไทย' },
+ 'tr': { data: tr, name: 'Türkçe' },
+ 'uk': { data: uk, name: 'Українська' },
+ 'uz': { data: uz, name: 'Oʻzbekcha' },
+ 'vi': { data: vi, name: 'Tiếng Việt' },
+ 'zh': { data: zh, name: '中文' },
+ 'zh_TW': { data: zh_TW, name: '中文 (Taiwan)' }
};
const languages = window.navigator.languages !== undefined ? window.navigator.languages.slice() : [];
@@ -114,20 +114,24 @@ languages.push(language);
languages.push(language.substring(0, 2));
languages.push('en');
for (let i = 0; i < languages.length; i++) {
- language = languages[i].replace('-', '_');
+ language = languages[i].replace('-', '_');
+ if (language in supportedLanguages) {
+ break;
+ }
+ if (language.length > 2) {
+ language = languages[i].substring(0, 2);
if (language in supportedLanguages) {
- break;
- }
- if (language.length > 2) {
- language = languages[i].substring(0, 2);
- if (language in supportedLanguages) {
- break;
- }
+ break;
}
+ }
}
const selectedLanguage = supportedLanguages[language];
+export const findStringKeys = (predicate) => {
+ return Object.keys(selectedLanguage.data).filter(predicate);
+}
+
export default key => {
- return selectedLanguage.data[key]
+ return selectedLanguage.data[key];
};
diff --git a/modern/src/common/stringUtils.js b/modern/src/common/stringUtils.js
new file mode 100644
index 00000000..7bd68c85
--- /dev/null
+++ b/modern/src/common/stringUtils.js
@@ -0,0 +1,7 @@
+export const prefixString = (prefix, value) => {
+ return prefix + value.charAt(0).toUpperCase() + value.slice(1);
+}
+
+export const unprefixString = (prefix, value) => {
+ return value.charAt(prefix.length).toLowerCase() + value.slice(prefix.length + 1);
+}