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
css
cssEnabled
locale
language
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,5 @@
import React, { useEffect, useState } from "react";
import { Button, Form } from "react-bootstrap";
import { countries } from "countries-list";
import { DurationInput, LoadingIndicator } from "src/components/Shared";
import { StashService } from "src/core/StashService";
import { useToast } from "src/hooks";
@@ -16,7 +15,6 @@ export const SettingsInterfacePanel: React.FC = () => {
const [css, setCSS] = useState<string>();
const [cssEnabled, setCSSEnabled] = useState<boolean>(false);
const [language, setLanguage] = useState<string>('en');
const [locale, setLocale] = useState<string>('US');
const [updateInterfaceConfig] = StashService.useConfigureInterface({
soundOnPreview,
@@ -26,8 +24,7 @@ export const SettingsInterfacePanel: React.FC = () => {
showStudioAsText,
css,
cssEnabled,
language,
locale
language
});
useEffect(() => {
@@ -39,8 +36,7 @@ export const SettingsInterfacePanel: React.FC = () => {
setShowStudioAsText(iCfg?.showStudioAsText ?? false);
setCSS(iCfg?.css ?? "");
setCSSEnabled(iCfg?.cssEnabled ?? false);
setLanguage(iCfg?.language ?? 'en');
setLocale(iCfg?.locale ?? 'en_US');
setLanguage(iCfg?.language ?? 'en-US');
}, [config]);
async function onSave() {
@@ -66,25 +62,13 @@ export const SettingsInterfacePanel: React.FC = () => {
<Form.Label className="col-2">Language</Form.Label>
<Form.Control
as="select"
className="col-2"
className="col-4"
value={language}
onChange={(e:React.FormEvent<HTMLSelectElement>) => setLanguage(e.currentTarget.value)}
>
<option value="en">English</option>
<option value="de">German</option>
</Form.Control>
</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>
))}
<option value="en-US">English (United States)</option>
<option value="en-GB">English (United Kingdom)</option>
<option value="de-DE">German</option>
</Form.Control>
</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 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 */
export type Scalars = {
@@ -113,7 +113,6 @@ export type ConfigInterfaceInput = {
css?: Maybe<Scalars['String']>,
cssEnabled?: Maybe<Scalars['Boolean']>,
language?: Maybe<Scalars['String']>,
locale?: Maybe<Scalars['String']>,
};
export type ConfigInterfaceResult = {
@@ -133,8 +132,6 @@ export type ConfigInterfaceResult = {
cssEnabled?: Maybe<Scalars['Boolean']>,
/** Interface language */
language?: Maybe<Scalars['String']>,
/** Interface locale */
locale?: Maybe<Scalars['String']>,
};
/** All configuration settings */
@@ -1158,7 +1155,7 @@ export type ConfigGeneralDataFragment = (
export type ConfigInterfaceDataFragment = (
{ __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 = (
@@ -2242,7 +2239,6 @@ export const ConfigInterfaceDataFragmentDoc = gql`
showStudioAsText
css
cssEnabled
locale
language
}
`;

View File

@@ -4442,11 +4442,6 @@ cosmiconfig@6.0.0, cosmiconfig@^6.0.0:
path-type "^4.0.0"
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:
version "4.0.3"
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff"