mirror of
https://github.com/wassname/talk.git
synced 2026-07-11 12:00:24 +08:00
Merge pull request #1650 from coralproject/whitelisted-langs
Added support for forcing languages
This commit is contained in:
+2
-1
@@ -7,6 +7,7 @@ ONBUILD ARG TALK_REPLY_COMMENTS_LOAD_DEPTH=3
|
||||
ONBUILD ARG TALK_THREADING_LEVEL=3
|
||||
ONBUILD ARG TALK_DEFAULT_STREAM_TAB=all
|
||||
ONBUILD ARG TALK_DEFAULT_LANG=en
|
||||
ONBUILD ARG TALK_WHITELISTED_LANGUAGES
|
||||
ONBUILD ARG TALK_PLUGINS_JSON
|
||||
ONBUILD ARG TALK_WEBPACK_SOURCE_MAP
|
||||
|
||||
@@ -20,4 +21,4 @@ ONBUILD COPY . /usr/src/app
|
||||
ONBUILD RUN cli plugins reconcile && \
|
||||
yarn && \
|
||||
yarn build && \
|
||||
yarn cache clean
|
||||
yarn cache clean
|
||||
|
||||
@@ -39,7 +39,20 @@ import pt_BR from '../../../locales/pt_BR.yml';
|
||||
import zh_CN from '../../../locales/zh_CN.yml';
|
||||
import zh_TW from '../../../locales/zh_TW.yml';
|
||||
|
||||
export const defaultLocale = process.env.TALK_DEFAULT_LANG.replace(/-/g, '_');
|
||||
// the list of languages that are whitelisted. If false, all languages that are
|
||||
// supported by Talk will be enabled.
|
||||
const whitelistedLanguages =
|
||||
process.env.TALK_WHITELISTED_LANGUAGES &&
|
||||
process.env.TALK_WHITELISTED_LANGUAGES.split(',').map(l => l.trim());
|
||||
|
||||
// The default language. If the whitelisted languages is specified and the
|
||||
// default language is not in that list, then the first language in the
|
||||
// whitelisted list will be used as the default.
|
||||
export const defaultLocale = whitelistedLanguages
|
||||
? !whitelistedLanguages.includes(process.env.TALK_DEFAULT_LANG)
|
||||
? whitelistedLanguages[0]
|
||||
: process.env.TALK_DEFAULT_LANG
|
||||
: process.env.TALK_DEFAULT_LANG;
|
||||
|
||||
export const translations = {
|
||||
...ar,
|
||||
@@ -64,10 +77,14 @@ let TIMEAGO_INSTANCE;
|
||||
// to the default language.
|
||||
const detectLanguage = () =>
|
||||
first(
|
||||
negotiateLanguages(navigator.languages, supportedLocales, {
|
||||
defaultLocale,
|
||||
strategy: 'lookup',
|
||||
})
|
||||
negotiateLanguages(
|
||||
navigator.languages,
|
||||
whitelistedLanguages || supportedLocales,
|
||||
{
|
||||
defaultLocale,
|
||||
strategy: 'lookup',
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
export function setupTranslations() {
|
||||
|
||||
@@ -36,6 +36,13 @@ const CONFIG = {
|
||||
// rendered text.
|
||||
DEFAULT_LANG: process.env.TALK_DEFAULT_LANG || 'en',
|
||||
|
||||
// WHITELISTED_LANGUAGES is a comma separated list of language/locales that
|
||||
// should be supported. If the default language is not included in the
|
||||
// whitelist list, the first entry will be used as the default.
|
||||
WHITELISTED_LANGUAGES:
|
||||
process.env.TALK_WHITELISTED_LANGUAGES &&
|
||||
process.env.TALK_WHITELISTED_LANGUAGES.split(',').map(l => l.trim()),
|
||||
|
||||
// When TRUE, it ensures that database indexes created in core will not add
|
||||
// indexes.
|
||||
CREATE_MONGO_INDEXES: process.env.DISABLE_CREATE_MONGO_INDEXES !== 'TRUE',
|
||||
@@ -317,6 +324,17 @@ CONFIG.JWT_COOKIE_NAMES = uniq(
|
||||
])
|
||||
);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Locale validation
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
if (
|
||||
CONFIG.WHITELISTED_LANGUAGES &&
|
||||
!CONFIG.WHITELISTED_LANGUAGES.includes(CONFIG.DEFAULT_LANG)
|
||||
) {
|
||||
CONFIG.DEFAULT_LANG = CONFIG.WHITELISTED_LANGUAGES[0];
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// External database url's
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -31,6 +31,21 @@ image you can specify it with `--build-arg TALK_DEFAULT_LANG=en`.
|
||||
|
||||
Specify the default translation language. (Default `en`)
|
||||
|
||||
## TALK_WHITELISTED_LANGUAGES
|
||||
|
||||
This is a **Build Variable** and must be consumed during build. If using the
|
||||
[Docker-onbuild](/talk/installation-from-docker/#onbuild)
|
||||
image you can specify it with `--build-arg TALK_WHITELISTED_LANGUAGES=en`.
|
||||
|
||||
Specify the comma separated whitelisted languages that you want the Talk
|
||||
application to serve. This will override the available set of languages that
|
||||
Talk will allow to be served.
|
||||
|
||||
If the [TALK_DEFAULT_LANG](#talk-default-lang) is not included in this list of
|
||||
whitelisted languages, then the first whitelisted language will become the
|
||||
default language. If this parameter is empty, then all languages supported by
|
||||
Talk will be whitelisted. (Default '')
|
||||
|
||||
## TALK_DEFAULT_STREAM_TAB
|
||||
|
||||
This is a **Build Variable** and must be consumed during build. If using the
|
||||
|
||||
+9
-5
@@ -8,7 +8,7 @@ const {
|
||||
const { first, get, has, merge, isUndefined } = require('lodash');
|
||||
const yaml = require('yamljs');
|
||||
const plugins = require('./plugins');
|
||||
const { DEFAULT_LANG } = require('../config');
|
||||
const { DEFAULT_LANG, WHITELISTED_LANGUAGES } = require('../config');
|
||||
|
||||
const resolve = (...paths) =>
|
||||
path.resolve(path.join(__dirname, '..', 'locales', ...paths));
|
||||
@@ -105,10 +105,14 @@ const i18n = {
|
||||
|
||||
// negotiate the language.
|
||||
const lang = first(
|
||||
negotiateLanguages(acceptsLanguages, supportedLocales, {
|
||||
defaultLocale: DEFAULT_LANG,
|
||||
strategy: 'lookup',
|
||||
})
|
||||
negotiateLanguages(
|
||||
acceptsLanguages,
|
||||
WHITELISTED_LANGUAGES || supportedLocales,
|
||||
{
|
||||
defaultLocale: DEFAULT_LANG,
|
||||
strategy: 'lookup',
|
||||
}
|
||||
)
|
||||
);
|
||||
debug(`decided language as '${lang}'`);
|
||||
|
||||
|
||||
@@ -169,6 +169,7 @@ const config = {
|
||||
TALK_REPLY_COMMENTS_LOAD_DEPTH: '3',
|
||||
TALK_DEFAULT_STREAM_TAB: 'all',
|
||||
TALK_DEFAULT_LANG: 'en',
|
||||
TALK_WHITELISTED_LANGUAGES: '',
|
||||
}),
|
||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user