Change i18n to just use single language setting

This commit is contained in:
Infinite
2020-02-08 22:02:07 +01:00
parent e6d9d385a7
commit 3a0420b79e
10 changed files with 13 additions and 61 deletions

View File

@@ -21,7 +21,6 @@ fragment ConfigInterfaceData on ConfigInterfaceResult {
showStudioAsText showStudioAsText
css css
cssEnabled cssEnabled
locale
language language
} }

View File

@@ -76,7 +76,6 @@ input ConfigInterfaceInput {
css: String css: String
cssEnabled: Boolean cssEnabled: Boolean
language: String language: String
locale: String
} }
type ConfigInterfaceResult { type ConfigInterfaceResult {
@@ -95,8 +94,6 @@ type ConfigInterfaceResult {
cssEnabled: Boolean cssEnabled: Boolean
"""Interface language""" """Interface language"""
language: String language: String
"""Interface locale"""
locale: String
} }
"""All configuration settings""" """All configuration settings"""

View File

@@ -110,10 +110,6 @@ func (r *mutationResolver) ConfigureInterface(ctx context.Context, input models.
config.Set(config.Language, *input.Language) config.Set(config.Language, *input.Language)
} }
if input.Locale != nil {
config.Set(config.Locale, *input.Locale)
}
css := "" css := ""
if input.CSS != nil { if input.CSS != nil {

View File

@@ -57,7 +57,6 @@ func makeConfigInterfaceResult() *models.ConfigInterfaceResult {
showStudioAsText := config.GetShowStudioAsText() showStudioAsText := config.GetShowStudioAsText()
css := config.GetCSS() css := config.GetCSS()
cssEnabled := config.GetCSSEnabled() cssEnabled := config.GetCSSEnabled()
locale := config.GetLocale()
language := config.GetLanguage() language := config.GetLanguage()
@@ -70,6 +69,5 @@ func makeConfigInterfaceResult() *models.ConfigInterfaceResult {
CSS: &css, CSS: &css,
CSSEnabled: &cssEnabled, CSSEnabled: &cssEnabled,
Language: &language, Language: &language,
Locale: &locale,
} }
} }

View File

@@ -34,7 +34,6 @@ const ExternalHost = "external_host"
// i18n // i18n
const Language = "language" const Language = "language"
const Locale = "locale"
// Interface options // Interface options
const SoundOnPreview = "sound_on_preview" const SoundOnPreview = "sound_on_preview"
@@ -106,18 +105,7 @@ func GetLanguage() string {
// default to English // default to English
if ret == "" { if ret == "" {
return "en" return "en-US"
}
return ret
}
func GetLocale() string {
ret := viper.GetString(Locale)
// default to US
if ret == "" {
return "US"
} }
return ret return ret

View File

@@ -36,7 +36,6 @@
"axios": "0.18.1", "axios": "0.18.1",
"bootstrap": "^4.4.1", "bootstrap": "^4.4.1",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"countries-list": "^2.5.1",
"formik": "^2.1.2", "formik": "^2.1.2",
"graphql": "^14.5.8", "graphql": "^14.5.8",
"graphql-tag": "^2.10.1", "graphql-tag": "^2.10.1",

View File

@@ -25,14 +25,14 @@ library.add(fas);
export const App: React.FC = () => { export const App: React.FC = () => {
const config = StashService.useConfiguration(); const config = StashService.useConfiguration();
const locale = config.data?.configuration?.interface?.locale ?? 'US'; const language = config.data?.configuration?.interface?.language ?? 'en-US';
const language = config.data?.configuration?.interface?.language ?? 'en'; const messageLanguage = language.slice(0,2);
const messages = flattenMessages((locales as any)[language] ?? locales.en); const messages = flattenMessages((locales as any)[messageLanguage]);
return ( return (
<div className="bp3-dark"> <div className="bp3-dark">
<ErrorBoundary> <ErrorBoundary>
<IntlProvider locale={locale} messages={messages}> <IntlProvider locale={language} messages={messages}>
<ToastProvider> <ToastProvider>
<MainNavbar /> <MainNavbar />
<div className="main container-fluid"> <div className="main container-fluid">

View File

@@ -1,6 +1,5 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Button, Form } from "react-bootstrap"; import { Button, Form } from "react-bootstrap";
import { countries } from "countries-list";
import { DurationInput, LoadingIndicator } from "src/components/Shared"; import { DurationInput, LoadingIndicator } from "src/components/Shared";
import { StashService } from "src/core/StashService"; import { StashService } from "src/core/StashService";
import { useToast } from "src/hooks"; import { useToast } from "src/hooks";
@@ -16,7 +15,6 @@ export const SettingsInterfacePanel: React.FC = () => {
const [css, setCSS] = useState<string>(); const [css, setCSS] = useState<string>();
const [cssEnabled, setCSSEnabled] = useState<boolean>(false); const [cssEnabled, setCSSEnabled] = useState<boolean>(false);
const [language, setLanguage] = useState<string>('en'); const [language, setLanguage] = useState<string>('en');
const [locale, setLocale] = useState<string>('US');
const [updateInterfaceConfig] = StashService.useConfigureInterface({ const [updateInterfaceConfig] = StashService.useConfigureInterface({
soundOnPreview, soundOnPreview,
@@ -26,8 +24,7 @@ export const SettingsInterfacePanel: React.FC = () => {
showStudioAsText, showStudioAsText,
css, css,
cssEnabled, cssEnabled,
language, language
locale
}); });
useEffect(() => { useEffect(() => {
@@ -39,8 +36,7 @@ export const SettingsInterfacePanel: React.FC = () => {
setShowStudioAsText(iCfg?.showStudioAsText ?? false); setShowStudioAsText(iCfg?.showStudioAsText ?? false);
setCSS(iCfg?.css ?? ""); setCSS(iCfg?.css ?? "");
setCSSEnabled(iCfg?.cssEnabled ?? false); setCSSEnabled(iCfg?.cssEnabled ?? false);
setLanguage(iCfg?.language ?? 'en'); setLanguage(iCfg?.language ?? 'en-US');
setLocale(iCfg?.locale ?? 'en_US');
}, [config]); }, [config]);
async function onSave() { async function onSave() {
@@ -66,25 +62,13 @@ export const SettingsInterfacePanel: React.FC = () => {
<Form.Label className="col-2">Language</Form.Label> <Form.Label className="col-2">Language</Form.Label>
<Form.Control <Form.Control
as="select" as="select"
className="col-2" className="col-4"
value={language} value={language}
onChange={(e:React.FormEvent<HTMLSelectElement>) => setLanguage(e.currentTarget.value)} onChange={(e:React.FormEvent<HTMLSelectElement>) => setLanguage(e.currentTarget.value)}
> >
<option value="en">English</option> <option value="en-US">English (United States)</option>
<option value="de">German</option> <option value="en-GB">English (United Kingdom)</option>
</Form.Control> <option value="de-DE">German</option>
</Form.Group>
<Form.Group controlId="region" className="row">
<Form.Label className="col-2">Region</Form.Label>
<Form.Control
as="select"
className="col-2"
value={locale}
onChange={(e:React.FormEvent<HTMLSelectElement>) => setLocale(e.currentTarget.value)}
>
{ Object.keys(countries).map(code => (
<option value={code}>{(countries as any)[code].name}</option>
))}
</Form.Control> </Form.Control>
</Form.Group> </Form.Group>
<Form.Group> <Form.Group>

View File

@@ -7,7 +7,7 @@ import * as ApolloReactHooks from '@apollo/react-hooks';
export type Maybe<T> = T | null; export type Maybe<T> = T | null;
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
// Generated in 2020-02-08T16:10:44+01:00 // Generated in 2020-02-08T21:46:36+01:00
/** All built-in and custom scalars, mapped to their actual values */ /** All built-in and custom scalars, mapped to their actual values */
export type Scalars = { export type Scalars = {
@@ -113,7 +113,6 @@ export type ConfigInterfaceInput = {
css?: Maybe<Scalars['String']>, css?: Maybe<Scalars['String']>,
cssEnabled?: Maybe<Scalars['Boolean']>, cssEnabled?: Maybe<Scalars['Boolean']>,
language?: Maybe<Scalars['String']>, language?: Maybe<Scalars['String']>,
locale?: Maybe<Scalars['String']>,
}; };
export type ConfigInterfaceResult = { export type ConfigInterfaceResult = {
@@ -133,8 +132,6 @@ export type ConfigInterfaceResult = {
cssEnabled?: Maybe<Scalars['Boolean']>, cssEnabled?: Maybe<Scalars['Boolean']>,
/** Interface language */ /** Interface language */
language?: Maybe<Scalars['String']>, language?: Maybe<Scalars['String']>,
/** Interface locale */
locale?: Maybe<Scalars['String']>,
}; };
/** All configuration settings */ /** All configuration settings */
@@ -1158,7 +1155,7 @@ export type ConfigGeneralDataFragment = (
export type ConfigInterfaceDataFragment = ( export type ConfigInterfaceDataFragment = (
{ __typename?: 'ConfigInterfaceResult' } { __typename?: 'ConfigInterfaceResult' }
& Pick<ConfigInterfaceResult, 'soundOnPreview' | 'wallShowTitle' | 'maximumLoopDuration' | 'autostartVideo' | 'showStudioAsText' | 'css' | 'cssEnabled' | 'locale' | 'language'> & Pick<ConfigInterfaceResult, 'soundOnPreview' | 'wallShowTitle' | 'maximumLoopDuration' | 'autostartVideo' | 'showStudioAsText' | 'css' | 'cssEnabled' | 'language'>
); );
export type ConfigDataFragment = ( export type ConfigDataFragment = (
@@ -2242,7 +2239,6 @@ export const ConfigInterfaceDataFragmentDoc = gql`
showStudioAsText showStudioAsText
css css
cssEnabled cssEnabled
locale
language language
} }
`; `;

View File

@@ -4442,11 +4442,6 @@ cosmiconfig@6.0.0, cosmiconfig@^6.0.0:
path-type "^4.0.0" path-type "^4.0.0"
yaml "^1.7.2" yaml "^1.7.2"
countries-list@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/countries-list/-/countries-list-2.5.1.tgz#784b7fb1a9fd116f1f8d00c307726d75a6a8d7ad"
integrity sha512-ht9obORj0Im7BqGfqlqTd7qLNMuuhdCvFMKmWx15ZQjpGVddd+018LOegE4J1wLtiZ5TYC/KhivkOYmelqSNLg==
create-ecdh@^4.0.0: create-ecdh@^4.0.0:
version "4.0.3" version "4.0.3"
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff" resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff"