mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-20 02:22:09 +00:00
refactor: move translateOption to a common file
This commit is contained in:
parent
ec338b16db
commit
fd08dcca06
5 changed files with 28 additions and 36 deletions
|
|
@ -30,6 +30,7 @@ const getVisibleChildrenRange = require('./getVisibleChildrenRange');
|
|||
const interfaceLanguages = require('./interfaceLanguages');
|
||||
const languageNames = require('./languageNames');
|
||||
const routesRegexp = require('./routesRegexp');
|
||||
const translateOption = require('./translateOption');
|
||||
const useAnimationFrame = require('./useAnimationFrame');
|
||||
const useBinaryState = require('./useBinaryState');
|
||||
const useFullscreen = require('./useFullscreen');
|
||||
|
|
@ -74,6 +75,7 @@ module.exports = {
|
|||
interfaceLanguages,
|
||||
languageNames,
|
||||
routesRegexp,
|
||||
translateOption,
|
||||
useAnimationFrame,
|
||||
useBinaryState,
|
||||
useFullscreen,
|
||||
|
|
|
|||
18
src/common/translateOption.js
Normal file
18
src/common/translateOption.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2017-2022 Smart code 203358507
|
||||
|
||||
const { t } = require('i18next');
|
||||
|
||||
const translateOption = (option, translateKeyPrefix = '') => {
|
||||
const translateKey = `${translateKeyPrefix}${option}`;
|
||||
const translateKeyUppercase = translateKey.toUpperCase();
|
||||
const translateValue = t(translateKey);
|
||||
const translateValueUppercase = t(translateKeyUppercase);
|
||||
if (translateKey !== translateValue) {
|
||||
return translateValue;
|
||||
} else if (translateKeyUppercase !== translateValueUppercase) {
|
||||
return translateValueUppercase;
|
||||
}
|
||||
return option.charAt(0).toUpperCase() + option.slice(1);
|
||||
};
|
||||
|
||||
module.exports = translateOption;
|
||||
|
|
@ -2,19 +2,7 @@
|
|||
|
||||
const React = require('react');
|
||||
const { t } = require('i18next');
|
||||
|
||||
const translateOption = (option, translateKeyPrefix = '') => {
|
||||
const translateKey = `${translateKeyPrefix}${option}`;
|
||||
const translateKeyUppercase = translateKey.toUpperCase();
|
||||
const translateValue = t(translateKey);
|
||||
const translateValueUppercase = t(translateKeyUppercase);
|
||||
if (translateKey !== translateValue) {
|
||||
return translateValue;
|
||||
} else if (translateKeyUppercase !== translateValueUppercase) {
|
||||
return translateValueUppercase;
|
||||
}
|
||||
return option.charAt(0).toUpperCase() + option.slice(1);
|
||||
};
|
||||
const { translateOption } = require('stremio/common');
|
||||
|
||||
const mapSelectableInputs = (installedAddons, remoteAddons) => {
|
||||
const catalogSelect = {
|
||||
|
|
|
|||
|
|
@ -2,15 +2,7 @@
|
|||
|
||||
const React = require('react');
|
||||
const { useTranslation } = require('react-i18next');
|
||||
|
||||
const translateOption = (t, option, translateKeyPrefix = '') => {
|
||||
const translateKey = `${translateKeyPrefix}${option}`;
|
||||
const translateValue = t(`${translateKeyPrefix}${option}`);
|
||||
if (translateKey !== translateValue) {
|
||||
return translateValue;
|
||||
}
|
||||
return option.charAt(0).toUpperCase() + option.slice(1);
|
||||
};
|
||||
const { translateOption } = require('stremio/common');
|
||||
|
||||
const mapSelectableInputs = (discover, t) => {
|
||||
const typeSelect = {
|
||||
|
|
@ -18,13 +10,13 @@ const mapSelectableInputs = (discover, t) => {
|
|||
options: discover.selectable.types
|
||||
.map(({ type, deepLinks }) => ({
|
||||
value: deepLinks.discover,
|
||||
label: translateOption(t, type, 'TYPE_')
|
||||
label: translateOption(type, 'TYPE_')
|
||||
})),
|
||||
selected: discover.selectable.types
|
||||
.filter(({ selected }) => selected)
|
||||
.map(({ deepLinks }) => deepLinks.discover),
|
||||
renderLabelText: discover.selected !== null ?
|
||||
() => translateOption(t, discover.selected.request.path.type, 'TYPE_')
|
||||
() => translateOption(discover.selected.request.path.type, 'TYPE_')
|
||||
:
|
||||
null,
|
||||
onSelect: (event) => {
|
||||
|
|
@ -58,7 +50,7 @@ const mapSelectableInputs = (discover, t) => {
|
|||
title: `Select ${name}`,
|
||||
isRequired: isRequired,
|
||||
options: options.map(({ value, deepLinks }) => ({
|
||||
label: typeof value === 'string' ? translateOption(t, value) : t('NONE'),
|
||||
label: typeof value === 'string' ? translateOption(value) : t('NONE'),
|
||||
value: JSON.stringify({
|
||||
href: deepLinks.discover,
|
||||
value
|
||||
|
|
|
|||
|
|
@ -2,15 +2,7 @@
|
|||
|
||||
const React = require('react');
|
||||
const { useTranslation } = require('react-i18next');
|
||||
|
||||
const translateOption = (t, option, translateKeyPrefix = '') => {
|
||||
const translateKey = `${translateKeyPrefix}${option}`;
|
||||
const translateValue = t(translateKey);
|
||||
if (translateKey !== translateValue) {
|
||||
return translateValue;
|
||||
}
|
||||
return option.charAt(0).toUpperCase() + option.slice(1);
|
||||
};
|
||||
const { translateOption } = require('stremio/common');
|
||||
|
||||
const mapSelectableInputs = (library, t) => {
|
||||
const typeSelect = {
|
||||
|
|
@ -18,7 +10,7 @@ const mapSelectableInputs = (library, t) => {
|
|||
options: library.selectable.types
|
||||
.map(({ type, deepLinks }) => ({
|
||||
value: deepLinks.library,
|
||||
label: type === null ? t('TYPE_ALL') : translateOption(t, type, 'TYPE_')
|
||||
label: type === null ? t('TYPE_ALL') : translateOption(type, 'TYPE_')
|
||||
})),
|
||||
selected: library.selectable.types
|
||||
.filter(({ selected }) => selected)
|
||||
|
|
@ -32,7 +24,7 @@ const mapSelectableInputs = (library, t) => {
|
|||
options: library.selectable.sorts
|
||||
.map(({ sort, deepLinks }) => ({
|
||||
value: deepLinks.library,
|
||||
label: translateOption(t, sort)
|
||||
label: translateOption(sort)
|
||||
})),
|
||||
selected: library.selectable.sorts
|
||||
.filter(({ selected }) => selected)
|
||||
|
|
|
|||
Loading…
Reference in a new issue