mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
feat(locale): Added a locale setting in Settings app
This removes the need to rebuild the phone in order to change language
This commit is contained in:
1 parent
5c6538b340
commit
a6e8c769c0
6 files changed
+82
-9
No files matched your search
+9
-2
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import './Phone.css';
|
||||
import './i18n';
|
||||
import { Route } from 'react-router-dom';
|
||||
@@ -33,11 +33,18 @@ import { usePhone } from './os/phone/hooks/usePhone';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
function Phone() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
|
||||
const { apps } = useApps();
|
||||
|
||||
const [settings] = useSettings();
|
||||
|
||||
// Set language from local storage
|
||||
// This will only trigger on first mount & settings changes
|
||||
useEffect(() => {
|
||||
i18n.changeLanguage(settings.language.value).catch((e) => console.error(e));
|
||||
}, [i18n, settings.language]);
|
||||
|
||||
useNuiService();
|
||||
useKeyboardService();
|
||||
usePhoneService();
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
LibraryMusic,
|
||||
VolumeUp,
|
||||
FileCopy,
|
||||
Book,
|
||||
} from '@material-ui/icons';
|
||||
|
||||
import { ListSubheader } from '@material-ui/core';
|
||||
@@ -86,6 +87,10 @@ export const SettingsApp = () => {
|
||||
),
|
||||
);
|
||||
|
||||
const languages = config.languages.map(
|
||||
MapSettingItem(settings.language, (val: SettingOption) => handleSettingChange('language', val)),
|
||||
);
|
||||
|
||||
const handleCopyPhoneNumber = () => {
|
||||
setClipboard(simcard.number);
|
||||
addAlert({
|
||||
@@ -101,7 +106,7 @@ export const SettingsApp = () => {
|
||||
<AppWrapper>
|
||||
<AppTitle app={settingsApp} />
|
||||
<AppContent backdrop={isMenuOpen} onClickBackdrop={closeMenu}>
|
||||
<List disablePadding subheader={<SubHeaderComp text="Phone" />}>
|
||||
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.PHONE')} />}>
|
||||
<SettingItemIconAction
|
||||
label={t('APPS_SETTINGS_PHONE_NUMBER')}
|
||||
labelSecondary={simcard.number}
|
||||
@@ -146,7 +151,14 @@ export const SettingsApp = () => {
|
||||
onClick={(curr) => handleSettingChange('streamerMode', !curr)}
|
||||
/>
|
||||
</List>
|
||||
<List disablePadding subheader={<SubHeaderComp text="Appearance" />}>
|
||||
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.APPEARANCE')} />}>
|
||||
<SettingItem
|
||||
label={t('SETTINGS.OPTIONS.LANGUAGE')}
|
||||
value={settings.language.label}
|
||||
options={languages}
|
||||
onClick={openMenu}
|
||||
icon={<Book />}
|
||||
/>
|
||||
<SettingItem
|
||||
label={t('APPS_SETTINGS_OPTION_THEME')}
|
||||
value={settings.theme.label}
|
||||
|
||||
@@ -26,6 +26,7 @@ export const settingsState = atom({
|
||||
});
|
||||
|
||||
export interface IPhoneSettings {
|
||||
language: SettingOption;
|
||||
wallpaper: SettingOption;
|
||||
frame: SettingOption;
|
||||
theme: SettingOption;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"cellProvider": "AT&T",
|
||||
"language": "en",
|
||||
"defaultLanguage": "en",
|
||||
"wallpapers": [
|
||||
{
|
||||
"label": "Minimal",
|
||||
@@ -67,6 +67,44 @@
|
||||
"value": 0.7
|
||||
}
|
||||
],
|
||||
"languages": [
|
||||
{
|
||||
"label": "English",
|
||||
"value": "en"
|
||||
},
|
||||
{
|
||||
"label": "Español",
|
||||
"value": "es"
|
||||
},
|
||||
{
|
||||
"label": "Français",
|
||||
"value": "fr"
|
||||
},
|
||||
{
|
||||
"label": "Türk",
|
||||
"value": "tr"
|
||||
},
|
||||
{
|
||||
"label": "Norsk",
|
||||
"value": "no"
|
||||
},
|
||||
{
|
||||
"label": "Svenska",
|
||||
"value": "sv"
|
||||
},
|
||||
{
|
||||
"label": "Português",
|
||||
"value": "pt"
|
||||
},
|
||||
{
|
||||
"label": "Português (BR)",
|
||||
"value": "ptbr"
|
||||
},
|
||||
{
|
||||
"label": "Bosanski",
|
||||
"value": "ba"
|
||||
}
|
||||
],
|
||||
"ringtones": [
|
||||
{
|
||||
"label": "Marimba",
|
||||
@@ -98,6 +136,10 @@
|
||||
}
|
||||
],
|
||||
"defaultSettings": {
|
||||
"language": {
|
||||
"label": "English",
|
||||
"value": "en"
|
||||
},
|
||||
"wallpaper": {
|
||||
"label": "Project Error",
|
||||
"value": "projecterror.jpg"
|
||||
@@ -107,7 +149,7 @@
|
||||
"value": "default.png"
|
||||
},
|
||||
"theme": {
|
||||
"label": "taso-dark",
|
||||
"label": "Taso Dark",
|
||||
"value": "taso-dark"
|
||||
},
|
||||
"zoom": {
|
||||
|
||||
+5
-3
@@ -27,9 +27,11 @@ i18n
|
||||
.use(initReactI18next) // passes i18n down to react-i18next
|
||||
.init({
|
||||
resources,
|
||||
lng: config.language,
|
||||
|
||||
keySeparator: false, // we do not use keys in form messages.welcome
|
||||
lng: config.defaultLanguage,
|
||||
react: {
|
||||
bindI18n: 'languageChanged',
|
||||
},
|
||||
keySeparator: '.', // we do not use keys in form messages.welcome
|
||||
|
||||
interpolation: {
|
||||
escapeValue: false, // react already safes from xss
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
"translation": {
|
||||
"DATE_FORMAT": "MM/DD/YYYY",
|
||||
"DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
|
||||
"SETTINGS": {
|
||||
"CATEGORY": {
|
||||
"APPEARANCE": "Appearance",
|
||||
"PHONE": "Phone"
|
||||
},
|
||||
"OPTIONS": {
|
||||
"LANGUAGE": "Language"
|
||||
}
|
||||
},
|
||||
|
||||
"COMING_SOON": "Coming soon...",
|
||||
"INITIALIZING": "Initializing",
|
||||
|
||||
Reference in new issue
Block a user