Add ability to support language subsets, with only CT and CS enabled for now.
CT - Chinese Traditional CS - Chinese Simplified Note that if English subsets like en-GB is enabled in the future, the default 'en' value used throughout the code (including in redux.git) needs to be changed to 'en-US'.
This commit is contained in:
parent
6a38f944a6
commit
ad0d96328b
4 changed files with 29 additions and 3 deletions
|
@ -3,10 +3,23 @@ import { app, BrowserWindow, dialog, shell, screen } from 'electron';
|
||||||
import isDev from 'electron-is-dev';
|
import isDev from 'electron-is-dev';
|
||||||
import windowStateKeeper from 'electron-window-state';
|
import windowStateKeeper from 'electron-window-state';
|
||||||
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
|
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
|
||||||
|
import { SUPPORTED_SUB_LANGUAGE_CODES, SUB_LANG_CODE_LEN } from 'constants/supported_sub_languages';
|
||||||
|
|
||||||
import setupBarMenu from './menu/setupBarMenu';
|
import setupBarMenu from './menu/setupBarMenu';
|
||||||
import * as PAGES from 'constants/pages';
|
import * as PAGES from 'constants/pages';
|
||||||
|
|
||||||
|
function GetAppLangCode() {
|
||||||
|
// 1. Gets the user locale.
|
||||||
|
// 2. Converts unsupported sub-languages to its primary (e.g. "en-GB" -> "en").
|
||||||
|
// Note that the primary itself may or may not be a supported language
|
||||||
|
// (up to clients to verify against SUPPORTED_LANGUAGES).
|
||||||
|
const langCode = app.getLocale();
|
||||||
|
if (langCode.length === SUB_LANG_CODE_LEN && !SUPPORTED_SUB_LANGUAGE_CODES.includes(langCode)) {
|
||||||
|
return langCode.slice(0, 2);
|
||||||
|
}
|
||||||
|
return langCode;
|
||||||
|
}
|
||||||
|
|
||||||
export default appState => {
|
export default appState => {
|
||||||
// Get primary display dimensions from Electron.
|
// Get primary display dimensions from Electron.
|
||||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
||||||
|
@ -144,7 +157,7 @@ export default appState => {
|
||||||
const language =
|
const language =
|
||||||
storedLanguage && storedLanguage !== 'undefined' && storedLanguage !== 'null'
|
storedLanguage && storedLanguage !== 'undefined' && storedLanguage !== 'null'
|
||||||
? storedLanguage
|
? storedLanguage
|
||||||
: app.getLocale().slice(0, 2);
|
: GetAppLangCode();
|
||||||
if (language !== 'en' && SUPPORTED_LANGUAGES[language]) {
|
if (language !== 'en' && SUPPORTED_LANGUAGES[language]) {
|
||||||
window.webContents.send('language-set', language);
|
window.webContents.send('language-set', language);
|
||||||
}
|
}
|
||||||
|
@ -185,7 +198,7 @@ export default appState => {
|
||||||
|
|
||||||
let dispUrl = url.replace(hoverUrlBase, lbryProto);
|
let dispUrl = url.replace(hoverUrlBase, lbryProto);
|
||||||
// Non-claims don't need the lbry protocol:
|
// Non-claims don't need the lbry protocol:
|
||||||
if (dispUrl === lbryProto) {
|
if (dispUrl === lbryProto) {
|
||||||
dispUrl = 'Home';
|
dispUrl = 'Home';
|
||||||
} else if (dispUrl.startsWith(lbryProto + '$/')) {
|
} else if (dispUrl.startsWith(lbryProto + '$/')) {
|
||||||
dispUrl = dispUrl.replace(lbryProto, '/');
|
dispUrl = dispUrl.replace(lbryProto, '/');
|
||||||
|
|
|
@ -181,6 +181,8 @@ const LANGUAGES = {
|
||||||
yo: ['Yoruba', 'Yorùbá'],
|
yo: ['Yoruba', 'Yorùbá'],
|
||||||
za: ['Zhuang', 'Cuengh / Tôô / 壮语'],
|
za: ['Zhuang', 'Cuengh / Tôô / 壮语'],
|
||||||
zh: ['Chinese', '中文'],
|
zh: ['Chinese', '中文'],
|
||||||
|
'zh-CN': ['Chinese (Simplified)', '中文 (简体)'],
|
||||||
|
'zh-TW': ['Chinese (Traditional)', '中文 (繁體)'],
|
||||||
zu: ['Zulu', 'isiZulu'],
|
zu: ['Zulu', 'isiZulu'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ import LANGUAGES from './languages';
|
||||||
const SUPPORTED_LANGUAGES = {
|
const SUPPORTED_LANGUAGES = {
|
||||||
en: LANGUAGES.en[1],
|
en: LANGUAGES.en[1],
|
||||||
da: LANGUAGES.da[1],
|
da: LANGUAGES.da[1],
|
||||||
zh: LANGUAGES.zh[1],
|
'zh-CN': LANGUAGES['zh-CN'][1],
|
||||||
|
'zh-TW': LANGUAGES['zh-TW'][1],
|
||||||
hr: LANGUAGES.hr[1],
|
hr: LANGUAGES.hr[1],
|
||||||
nl: LANGUAGES.nl[1],
|
nl: LANGUAGES.nl[1],
|
||||||
fr: LANGUAGES.fr[1],
|
fr: LANGUAGES.fr[1],
|
||||||
|
@ -33,4 +34,6 @@ const SUPPORTED_LANGUAGES = {
|
||||||
uk: LANGUAGES.uk[1],
|
uk: LANGUAGES.uk[1],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Properties: language code (e.g. 'ja')
|
||||||
|
// Values: name of the language in native form (e.g. '日本語')
|
||||||
export default SUPPORTED_LANGUAGES;
|
export default SUPPORTED_LANGUAGES;
|
||||||
|
|
8
ui/constants/supported_sub_languages.js
Normal file
8
ui/constants/supported_sub_languages.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// https://www.electronjs.org/docs/api/locales
|
||||||
|
|
||||||
|
export const SUB_LANG_CODE_LEN = 5;
|
||||||
|
|
||||||
|
export const SUPPORTED_SUB_LANGUAGE_CODES = [
|
||||||
|
'zh-CN',
|
||||||
|
'zh-TW',
|
||||||
|
];
|
Loading…
Reference in a new issue