zh languages

bugfix

bugfix3

publish

add zh back for homepage selector

test

revert i18n file

DRY publish language
This commit is contained in:
zeppi 2021-01-06 13:13:56 -05:00 committed by Sean Yesmunt
parent 7c3ff32496
commit 6fb345dbbc
14 changed files with 93 additions and 51 deletions

View file

@ -4,21 +4,23 @@ import isDev from 'electron-is-dev';
import windowStateKeeper from 'electron-window-state';
import SUPPORTED_LANGUAGES from 'constants/supported_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 setupBarMenu from './menu/setupBarMenu';
import * as PAGES from 'constants/pages';
function GetAppLangCode() {
// https://www.electronjs.org/docs/api/locales
// 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 SUPPORTED_BROWSER_LANGUAGES[langCode.slice(0, 2)];
}
return langCode;
return SUPPORTED_BROWSER_LANGUAGES[langCode];
}
export default appState => {

View file

@ -36,6 +36,7 @@ import {
STATUS_FAILING,
STATUS_DOWN,
} from 'web/effects/use-degraded-performance';
import LANGUAGE_MIGRATIONS from 'constants/language-migrations';
// @endif
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
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 useCustomScrollbar = !IS_MAC;
const shouldMigrateLanguage = LANGUAGE_MIGRATIONS[language];
let uri;
try {
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
}, [language, languages]);
useEffect(() => {
if (shouldMigrateLanguage) {
setLanguage(shouldMigrateLanguage);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shouldMigrateLanguage]);
useEffect(() => {
// 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

View file

@ -4,7 +4,7 @@ import React from 'react';
import homepages from 'homepages';
import LANGUAGES from 'constants/languages';
import { FormField } from 'component/common/form';
import { getDefaultHomepage } from 'util/default-languages';
import { getDefaultHomepageKey } from 'util/default-languages';
type Props = {
homepage: string,
@ -28,7 +28,7 @@ function SelectHomepage(props: Props) {
type="select"
label={__('Homepage')}
onChange={handleSetHomepage}
value={homepage || getDefaultHomepage()}
value={homepage || getDefaultHomepageKey()}
helper={__('Tailor your experience.')}
>
{Object.keys(homepages).map(hp => (

View file

@ -6,6 +6,8 @@ import { FormField } from 'component/common/form';
import Button from 'component/button';
import LicenseType from './license-type';
import Card from 'component/common/card';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
// @if TARGET='app'
// import ErrorText from 'component/common/error-text';
// import { LbryFirst } from 'lbry-redux';
@ -156,34 +158,12 @@ function PublishAdditionalOptions(props: Props) {
value={language}
onChange={event => updatePublishForm({ language: event.target.value })}
>
<option value="en">{__('English')}</option>
<option value="zh">{__('Chinese')}</option>
<option value="fr">{__('French')}</option>
<option value="de">{__('German')}</option>
<option value="ja">{__('Japanese')}</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>
{Object.entries(SUPPORTED_LANGUAGES).map(([langkey, langName]) => (
// $FlowFixMe
<option key={langkey} value={langkey}>
{langName}
</option>
))}
</FormField>
<LicenseType

View file

@ -0,0 +1,6 @@
const LANGUAGE_MIGRATIONS = {
'zh-CN': 'zh-Hans',
'zh-TW': 'zh-Hant',
};
export default LANGUAGE_MIGRATIONS;

View file

@ -181,8 +181,8 @@ const LANGUAGES = {
yo: ['Yoruba', 'Yorùbá'],
za: ['Zhuang', 'Cuengh / Tôô / 壮语'],
zh: ['Chinese', '中文'],
'zh-CN': ['Chinese (Simplified)', '中文 (简体)'],
'zh-TW': ['Chinese (Traditional)', '中文 (繁體)'],
'zh-Hans': ['Chinese (Simplified)', '中文 (简体)'],
'zh-Hant': ['Chinese (Traditional)', '中文 (繁體)'],
zu: ['Zulu', 'isiZulu'],
};

View 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;

View file

@ -1,10 +1,10 @@
import LANGUAGES from './languages';
// supported_browser_languages
const SUPPORTED_LANGUAGES = {
en: LANGUAGES.en[1],
da: LANGUAGES.da[1],
'zh-CN': LANGUAGES['zh-CN'][1],
'zh-TW': LANGUAGES['zh-TW'][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],

View file

@ -86,7 +86,6 @@ export function __(message, tokens) {
const language = localStorageAvailable
? window.localStorage.getItem('language') || 'en'
: window.navigator.language.slice(0, 2) || 'en';
if (!isProduction) {
IS_WEB ? saveMessageWeb(message) : saveMessageDesktop(message);
}

View file

@ -9,6 +9,7 @@ import { doGetSyncDesktop, doSyncUnsubscribe, doSetSyncLock } from 'redux/action
import { doAlertWaitingForSync, doGetAndPopulatePreferences } from 'redux/actions/app';
import { selectPrefsReady } from 'redux/selectors/sync';
import { Lbryio } from 'lbryinc';
import { getDefaultLanguage } from 'util/default-languages';
const { DEFAULT_LANGUAGE } = require('config');
const { SDK_SYNC_KEYS } = SHARED_PREFERENCES;
@ -295,7 +296,7 @@ export function doFetchLanguage(language) {
export function doSetHomepage(code) {
return (dispatch, getState) => {
let languageCode;
if (code === window.navigator.language.slice(0, 2)) {
if (code === getDefaultLanguage()) {
languageCode = null;
} else {
languageCode = code;
@ -311,7 +312,7 @@ export function doSetLanguage(language) {
const { share_usage_data: shareSetting } = daemonSettings;
const isSharingData = shareSetting || IS_WEB;
let languageSetting;
if (language === window.navigator.language.slice(0, 2)) {
if (language === getDefaultLanguage()) {
languageSetting = null;
} else {
languageSetting = language;

View file

@ -6,6 +6,7 @@ import { doToast } from 'redux/actions/notifications';
import rewards from 'rewards';
import { Lbryio } from 'lbryinc';
import { DOMAIN } from 'config';
import { getDefaultLanguage } from 'util/default-languages';
const AUTH_IN_PROGRESS = 'authInProgress';
export let sessionStorageAvailable = false;
@ -131,7 +132,7 @@ export function doAuthenticate(
});
checkAuthBusy()
.then(() => {
return Lbryio.authenticate(DOMAIN, window.navigator.language.slice(0, 2) || 'en');
return Lbryio.authenticate(DOMAIN, getDefaultLanguage());
})
.then(user => {
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);

View file

@ -2,6 +2,7 @@ import * as ACTIONS from 'constants/action_types';
import moment from 'moment';
import { ACTIONS as LBRY_REDUX_ACTIONS, SETTINGS, SHARED_PREFERENCES } from 'lbry-redux';
import { getSubsetFromKeysArray } from 'util/sync-settings';
import { getDefaultLanguage } from 'util/default-languages';
import { UNSYNCED_SETTINGS } from 'config';
const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
@ -16,7 +17,7 @@ try {
let appLanguage = window.localStorage.getItem(SETTINGS.LANGUAGE);
settingLanguage.push(appLanguage);
} catch (e) {}
settingLanguage.push(window.navigator.language.slice(0, 2));
settingLanguage.push(getDefaultLanguage());
settingLanguage.push('en');
const defaultState = {

View file

@ -1,7 +1,7 @@
import { SETTINGS, DAEMON_SETTINGS } from 'lbry-redux';
import { createSelector } from 'reselect';
import homepages from 'homepages';
import { getDefaultHomepage, getDefaultLanguage } from 'util/default-languages';
import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages';
const selectState = state => state.settings || {};
@ -55,7 +55,7 @@ export const selectThemePath = createSelector(
);
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 => {

View file

@ -1,13 +1,14 @@
import homepages from 'homepages';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import SUPPORTED_BROWSER_LANGUAGES from 'constants/supported_browser_languages';
const DEFAULT_LANG = 'en';
export const getDefaultHomepage = () => {
return homepages[window.navigator.language.slice(0, 2)] ? window.navigator.language.slice(0, 2) : DEFAULT_LANG;
export const getDefaultLanguage = () => {
const browserLanguage = window.navigator.language;
return SUPPORTED_BROWSER_LANGUAGES[browserLanguage] || DEFAULT_LANG;
};
export const getDefaultLanguage = () => {
return SUPPORTED_LANGUAGES[window.navigator.language.slice(0, 2)]
? window.navigator.language.slice(0, 2)
: DEFAULT_LANG;
// If homepages has a key "zh-Hant" return that, otherwise return "zh", otherwise "en"
export const getDefaultHomepageKey = () => {
const language = getDefaultLanguage();
return (homepages[language] && language) || (homepages[language.slice(0, 2)] && language.slice(0, 2)) || DEFAULT_LANG;
};