zh languages
bugfix bugfix3 publish add zh back for homepage selector test revert i18n file DRY publish language
This commit is contained in:
parent
7c3ff32496
commit
6fb345dbbc
14 changed files with 93 additions and 51 deletions
|
@ -4,21 +4,23 @@ 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 { SUPPORTED_SUB_LANGUAGE_CODES, SUB_LANG_CODE_LEN } from 'constants/supported_sub_languages';
|
||||||
|
import { SUPPORTED_BROWSER_LANGUAGES } from 'constants/supported_browser_languages';
|
||||||
import { TO_TRAY_WHEN_CLOSED } from 'constants/settings';
|
import { TO_TRAY_WHEN_CLOSED } from 'constants/settings';
|
||||||
|
|
||||||
import setupBarMenu from './menu/setupBarMenu';
|
import setupBarMenu from './menu/setupBarMenu';
|
||||||
import * as PAGES from 'constants/pages';
|
import * as PAGES from 'constants/pages';
|
||||||
|
|
||||||
function GetAppLangCode() {
|
function GetAppLangCode() {
|
||||||
|
// https://www.electronjs.org/docs/api/locales
|
||||||
// 1. Gets the user locale.
|
// 1. Gets the user locale.
|
||||||
// 2. Converts unsupported sub-languages to its primary (e.g. "en-GB" -> "en").
|
// 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
|
// Note that the primary itself may or may not be a supported language
|
||||||
// (up to clients to verify against SUPPORTED_LANGUAGES).
|
// (up to clients to verify against SUPPORTED_LANGUAGES).
|
||||||
const langCode = app.getLocale();
|
const langCode = app.getLocale();
|
||||||
if (langCode.length === SUB_LANG_CODE_LEN && !SUPPORTED_SUB_LANGUAGE_CODES.includes(langCode)) {
|
if (langCode.length === SUB_LANG_CODE_LEN && !SUPPORTED_SUB_LANGUAGE_CODES.includes(langCode)) {
|
||||||
return langCode.slice(0, 2);
|
return SUPPORTED_BROWSER_LANGUAGES[langCode.slice(0, 2)];
|
||||||
}
|
}
|
||||||
return langCode;
|
return SUPPORTED_BROWSER_LANGUAGES[langCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default appState => {
|
export default appState => {
|
||||||
|
|
|
@ -36,6 +36,7 @@ import {
|
||||||
STATUS_FAILING,
|
STATUS_FAILING,
|
||||||
STATUS_DOWN,
|
STATUS_DOWN,
|
||||||
} from 'web/effects/use-degraded-performance';
|
} from 'web/effects/use-degraded-performance';
|
||||||
|
import LANGUAGE_MIGRATIONS from 'constants/language-migrations';
|
||||||
// @endif
|
// @endif
|
||||||
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
|
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
|
||||||
export const IS_MAC = navigator.userAgent.indexOf('Mac OS X') !== -1;
|
export const IS_MAC = navigator.userAgent.indexOf('Mac OS X') !== -1;
|
||||||
|
@ -134,6 +135,8 @@ function App(props: Props) {
|
||||||
const userId = user && user.id;
|
const userId = user && user.id;
|
||||||
const useCustomScrollbar = !IS_MAC;
|
const useCustomScrollbar = !IS_MAC;
|
||||||
|
|
||||||
|
const shouldMigrateLanguage = LANGUAGE_MIGRATIONS[language];
|
||||||
|
|
||||||
let uri;
|
let uri;
|
||||||
try {
|
try {
|
||||||
const newpath = buildURI(parseURI(pathname.slice(1).replace(/:/g, '#')));
|
const newpath = buildURI(parseURI(pathname.slice(1).replace(/:/g, '#')));
|
||||||
|
@ -232,6 +235,13 @@ function App(props: Props) {
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [language, languages]);
|
}, [language, languages]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (shouldMigrateLanguage) {
|
||||||
|
setLanguage(shouldMigrateLanguage);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [shouldMigrateLanguage]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Check that previousHasVerifiedEmail was not undefined instead of just not truthy
|
// Check that previousHasVerifiedEmail was not undefined instead of just not truthy
|
||||||
// This ensures we don't fire the emailVerified event on the initial user fetch
|
// This ensures we don't fire the emailVerified event on the initial user fetch
|
||||||
|
|
|
@ -4,7 +4,7 @@ import React from 'react';
|
||||||
import homepages from 'homepages';
|
import homepages from 'homepages';
|
||||||
import LANGUAGES from 'constants/languages';
|
import LANGUAGES from 'constants/languages';
|
||||||
import { FormField } from 'component/common/form';
|
import { FormField } from 'component/common/form';
|
||||||
import { getDefaultHomepage } from 'util/default-languages';
|
import { getDefaultHomepageKey } from 'util/default-languages';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
homepage: string,
|
homepage: string,
|
||||||
|
@ -28,7 +28,7 @@ function SelectHomepage(props: Props) {
|
||||||
type="select"
|
type="select"
|
||||||
label={__('Homepage')}
|
label={__('Homepage')}
|
||||||
onChange={handleSetHomepage}
|
onChange={handleSetHomepage}
|
||||||
value={homepage || getDefaultHomepage()}
|
value={homepage || getDefaultHomepageKey()}
|
||||||
helper={__('Tailor your experience.')}
|
helper={__('Tailor your experience.')}
|
||||||
>
|
>
|
||||||
{Object.keys(homepages).map(hp => (
|
{Object.keys(homepages).map(hp => (
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { FormField } from 'component/common/form';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
import LicenseType from './license-type';
|
import LicenseType from './license-type';
|
||||||
import Card from 'component/common/card';
|
import Card from 'component/common/card';
|
||||||
|
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
|
||||||
|
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
// import ErrorText from 'component/common/error-text';
|
// import ErrorText from 'component/common/error-text';
|
||||||
// import { LbryFirst } from 'lbry-redux';
|
// import { LbryFirst } from 'lbry-redux';
|
||||||
|
@ -156,34 +158,12 @@ function PublishAdditionalOptions(props: Props) {
|
||||||
value={language}
|
value={language}
|
||||||
onChange={event => updatePublishForm({ language: event.target.value })}
|
onChange={event => updatePublishForm({ language: event.target.value })}
|
||||||
>
|
>
|
||||||
<option value="en">{__('English')}</option>
|
{Object.entries(SUPPORTED_LANGUAGES).map(([langkey, langName]) => (
|
||||||
<option value="zh">{__('Chinese')}</option>
|
// $FlowFixMe
|
||||||
<option value="fr">{__('French')}</option>
|
<option key={langkey} value={langkey}>
|
||||||
<option value="de">{__('German')}</option>
|
{langName}
|
||||||
<option value="ja">{__('Japanese')}</option>
|
</option>
|
||||||
<option value="ru">{__('Russian')}</option>
|
))}
|
||||||
<option value="es">{__('Spanish')}</option>
|
|
||||||
<option value="id">{__('Indonesian')}</option>
|
|
||||||
<option value="fi">{__('Finnish')}</option>
|
|
||||||
<option value="kn">{__('Kannada')}</option>
|
|
||||||
<option value="it">{__('Italian')}</option>
|
|
||||||
<option value="nl">{__('Dutch')}</option>
|
|
||||||
<option value="tr">{__('Turkish')}</option>
|
|
||||||
<option value="pl">{__('Polish')}</option>
|
|
||||||
<option value="ms">{__('Malay')}</option>
|
|
||||||
<option value="pt">{__('Portuguese')}</option>
|
|
||||||
<option value="vi">{__('Vietnamese')}</option>
|
|
||||||
<option value="th">{__('Thai')}</option>
|
|
||||||
<option value="ar">{__('Arabic')}</option>
|
|
||||||
<option value="cs">{__('Czech')}</option>
|
|
||||||
<option value="hr">{__('Croatian')}</option>
|
|
||||||
<option value="km">{__('Khmer')}</option>
|
|
||||||
<option value="ko">{__('Korean')}</option>
|
|
||||||
<option value="no">{__('Norwegian')}</option>
|
|
||||||
<option value="ro">{__('Romanian')}</option>
|
|
||||||
<option value="hi">{__('Hindi')}</option>
|
|
||||||
<option value="el">{__('Greek')}</option>
|
|
||||||
<option value="fa">{__('Persian')}</option>
|
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<LicenseType
|
<LicenseType
|
||||||
|
|
6
ui/constants/language-migrations.js
Normal file
6
ui/constants/language-migrations.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
const LANGUAGE_MIGRATIONS = {
|
||||||
|
'zh-CN': 'zh-Hans',
|
||||||
|
'zh-TW': 'zh-Hant',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LANGUAGE_MIGRATIONS;
|
|
@ -181,8 +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-Hans': ['Chinese (Simplified)', '中文 (简体)'],
|
||||||
'zh-TW': ['Chinese (Traditional)', '中文 (繁體)'],
|
'zh-Hant': ['Chinese (Traditional)', '中文 (繁體)'],
|
||||||
zu: ['Zulu', 'isiZulu'],
|
zu: ['Zulu', 'isiZulu'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
41
ui/constants/supported_browser_languages.js
Normal file
41
ui/constants/supported_browser_languages.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import LANGUAGES from './languages';
|
||||||
|
|
||||||
|
const SUPPORTED_BROWSER_LANGUAGES = {
|
||||||
|
en: LANGUAGES.en[1],
|
||||||
|
da: LANGUAGES.da[1],
|
||||||
|
'zh-CN': LANGUAGES['zh-Hans'][1],
|
||||||
|
'zh-TW': LANGUAGES['zh-Hant'][1],
|
||||||
|
'zh-Hans': LANGUAGES['zh-Hans'][1],
|
||||||
|
'zh-Hant': LANGUAGES['zh-Hant'][1],
|
||||||
|
hr: LANGUAGES.hr[1],
|
||||||
|
nl: LANGUAGES.nl[1],
|
||||||
|
fr: LANGUAGES.fr[1],
|
||||||
|
de: LANGUAGES.de[1],
|
||||||
|
gu: LANGUAGES.gu[1],
|
||||||
|
hi: LANGUAGES.hi[1],
|
||||||
|
id: LANGUAGES.id[1],
|
||||||
|
jv: LANGUAGES.jv[1],
|
||||||
|
it: LANGUAGES.it[1],
|
||||||
|
ms: LANGUAGES.ms[1],
|
||||||
|
ml: LANGUAGES.ml[1],
|
||||||
|
mr: LANGUAGES.mr[1],
|
||||||
|
pa: LANGUAGES.pa[1],
|
||||||
|
pl: LANGUAGES.pl[1],
|
||||||
|
pt: LANGUAGES.pt[1],
|
||||||
|
ro: LANGUAGES.ro[1],
|
||||||
|
ru: LANGUAGES.ru[1],
|
||||||
|
sr: LANGUAGES.sr[1],
|
||||||
|
sk: LANGUAGES.sk[1],
|
||||||
|
ur: LANGUAGES.ur[1],
|
||||||
|
ca: LANGUAGES.ca[1],
|
||||||
|
es: LANGUAGES.es[1],
|
||||||
|
sv: LANGUAGES.sv[1],
|
||||||
|
tr: LANGUAGES.tr[1],
|
||||||
|
cs: LANGUAGES.cs[1],
|
||||||
|
kn: LANGUAGES.kn[1],
|
||||||
|
uk: LANGUAGES.uk[1],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Properties: language code (e.g. 'ja')
|
||||||
|
// Values: name of the language in native form (e.g. '日本語')
|
||||||
|
export default SUPPORTED_BROWSER_LANGUAGES;
|
|
@ -1,10 +1,10 @@
|
||||||
import LANGUAGES from './languages';
|
import LANGUAGES from './languages';
|
||||||
|
// supported_browser_languages
|
||||||
const SUPPORTED_LANGUAGES = {
|
const SUPPORTED_LANGUAGES = {
|
||||||
en: LANGUAGES.en[1],
|
en: LANGUAGES.en[1],
|
||||||
da: LANGUAGES.da[1],
|
da: LANGUAGES.da[1],
|
||||||
'zh-CN': LANGUAGES['zh-CN'][1],
|
'zh-Hans': LANGUAGES['zh-Hans'][1],
|
||||||
'zh-TW': LANGUAGES['zh-TW'][1],
|
'zh-Hant': LANGUAGES['zh-Hant'][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],
|
||||||
|
|
|
@ -86,7 +86,6 @@ export function __(message, tokens) {
|
||||||
const language = localStorageAvailable
|
const language = localStorageAvailable
|
||||||
? window.localStorage.getItem('language') || 'en'
|
? window.localStorage.getItem('language') || 'en'
|
||||||
: window.navigator.language.slice(0, 2) || 'en';
|
: window.navigator.language.slice(0, 2) || 'en';
|
||||||
|
|
||||||
if (!isProduction) {
|
if (!isProduction) {
|
||||||
IS_WEB ? saveMessageWeb(message) : saveMessageDesktop(message);
|
IS_WEB ? saveMessageWeb(message) : saveMessageDesktop(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { doGetSyncDesktop, doSyncUnsubscribe, doSetSyncLock } from 'redux/action
|
||||||
import { doAlertWaitingForSync, doGetAndPopulatePreferences } from 'redux/actions/app';
|
import { doAlertWaitingForSync, doGetAndPopulatePreferences } from 'redux/actions/app';
|
||||||
import { selectPrefsReady } from 'redux/selectors/sync';
|
import { selectPrefsReady } from 'redux/selectors/sync';
|
||||||
import { Lbryio } from 'lbryinc';
|
import { Lbryio } from 'lbryinc';
|
||||||
|
import { getDefaultLanguage } from 'util/default-languages';
|
||||||
|
|
||||||
const { DEFAULT_LANGUAGE } = require('config');
|
const { DEFAULT_LANGUAGE } = require('config');
|
||||||
const { SDK_SYNC_KEYS } = SHARED_PREFERENCES;
|
const { SDK_SYNC_KEYS } = SHARED_PREFERENCES;
|
||||||
|
@ -295,7 +296,7 @@ export function doFetchLanguage(language) {
|
||||||
export function doSetHomepage(code) {
|
export function doSetHomepage(code) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
let languageCode;
|
let languageCode;
|
||||||
if (code === window.navigator.language.slice(0, 2)) {
|
if (code === getDefaultLanguage()) {
|
||||||
languageCode = null;
|
languageCode = null;
|
||||||
} else {
|
} else {
|
||||||
languageCode = code;
|
languageCode = code;
|
||||||
|
@ -311,7 +312,7 @@ export function doSetLanguage(language) {
|
||||||
const { share_usage_data: shareSetting } = daemonSettings;
|
const { share_usage_data: shareSetting } = daemonSettings;
|
||||||
const isSharingData = shareSetting || IS_WEB;
|
const isSharingData = shareSetting || IS_WEB;
|
||||||
let languageSetting;
|
let languageSetting;
|
||||||
if (language === window.navigator.language.slice(0, 2)) {
|
if (language === getDefaultLanguage()) {
|
||||||
languageSetting = null;
|
languageSetting = null;
|
||||||
} else {
|
} else {
|
||||||
languageSetting = language;
|
languageSetting = language;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { doToast } from 'redux/actions/notifications';
|
||||||
import rewards from 'rewards';
|
import rewards from 'rewards';
|
||||||
import { Lbryio } from 'lbryinc';
|
import { Lbryio } from 'lbryinc';
|
||||||
import { DOMAIN } from 'config';
|
import { DOMAIN } from 'config';
|
||||||
|
import { getDefaultLanguage } from 'util/default-languages';
|
||||||
const AUTH_IN_PROGRESS = 'authInProgress';
|
const AUTH_IN_PROGRESS = 'authInProgress';
|
||||||
export let sessionStorageAvailable = false;
|
export let sessionStorageAvailable = false;
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ export function doAuthenticate(
|
||||||
});
|
});
|
||||||
checkAuthBusy()
|
checkAuthBusy()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return Lbryio.authenticate(DOMAIN, window.navigator.language.slice(0, 2) || 'en');
|
return Lbryio.authenticate(DOMAIN, getDefaultLanguage());
|
||||||
})
|
})
|
||||||
.then(user => {
|
.then(user => {
|
||||||
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);
|
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as ACTIONS from 'constants/action_types';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { ACTIONS as LBRY_REDUX_ACTIONS, SETTINGS, SHARED_PREFERENCES } from 'lbry-redux';
|
import { ACTIONS as LBRY_REDUX_ACTIONS, SETTINGS, SHARED_PREFERENCES } from 'lbry-redux';
|
||||||
import { getSubsetFromKeysArray } from 'util/sync-settings';
|
import { getSubsetFromKeysArray } from 'util/sync-settings';
|
||||||
|
import { getDefaultLanguage } from 'util/default-languages';
|
||||||
import { UNSYNCED_SETTINGS } from 'config';
|
import { UNSYNCED_SETTINGS } from 'config';
|
||||||
|
|
||||||
const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
|
const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
|
||||||
|
@ -16,7 +17,7 @@ try {
|
||||||
let appLanguage = window.localStorage.getItem(SETTINGS.LANGUAGE);
|
let appLanguage = window.localStorage.getItem(SETTINGS.LANGUAGE);
|
||||||
settingLanguage.push(appLanguage);
|
settingLanguage.push(appLanguage);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
settingLanguage.push(window.navigator.language.slice(0, 2));
|
settingLanguage.push(getDefaultLanguage());
|
||||||
settingLanguage.push('en');
|
settingLanguage.push('en');
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { SETTINGS, DAEMON_SETTINGS } from 'lbry-redux';
|
import { SETTINGS, DAEMON_SETTINGS } from 'lbry-redux';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import homepages from 'homepages';
|
import homepages from 'homepages';
|
||||||
import { getDefaultHomepage, getDefaultLanguage } from 'util/default-languages';
|
import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages';
|
||||||
|
|
||||||
const selectState = state => state.settings || {};
|
const selectState = state => state.settings || {};
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ export const selectThemePath = createSelector(
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectHomepageCode = createSelector(makeSelectClientSetting(SETTINGS.HOMEPAGE), setting => {
|
export const selectHomepageCode = createSelector(makeSelectClientSetting(SETTINGS.HOMEPAGE), setting => {
|
||||||
return homepages[setting] ? setting : getDefaultHomepage();
|
return homepages[setting] ? setting : getDefaultHomepageKey();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const selectLanguage = createSelector(makeSelectClientSetting(SETTINGS.LANGUAGE), setting => {
|
export const selectLanguage = createSelector(makeSelectClientSetting(SETTINGS.LANGUAGE), setting => {
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import homepages from 'homepages';
|
import homepages from 'homepages';
|
||||||
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
|
import SUPPORTED_BROWSER_LANGUAGES from 'constants/supported_browser_languages';
|
||||||
const DEFAULT_LANG = 'en';
|
const DEFAULT_LANG = 'en';
|
||||||
|
|
||||||
export const getDefaultHomepage = () => {
|
export const getDefaultLanguage = () => {
|
||||||
return homepages[window.navigator.language.slice(0, 2)] ? window.navigator.language.slice(0, 2) : DEFAULT_LANG;
|
const browserLanguage = window.navigator.language;
|
||||||
|
return SUPPORTED_BROWSER_LANGUAGES[browserLanguage] || DEFAULT_LANG;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDefaultLanguage = () => {
|
// If homepages has a key "zh-Hant" return that, otherwise return "zh", otherwise "en"
|
||||||
return SUPPORTED_LANGUAGES[window.navigator.language.slice(0, 2)]
|
export const getDefaultHomepageKey = () => {
|
||||||
? window.navigator.language.slice(0, 2)
|
const language = getDefaultLanguage();
|
||||||
: DEFAULT_LANG;
|
return (homepages[language] && language) || (homepages[language.slice(0, 2)] && language.slice(0, 2)) || DEFAULT_LANG;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue