Skip to content

Commit a20d2fe

Browse files
committed
fix(settings): language not updated
1 parent a58f6ab commit a20d2fe

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

i18n/en.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
"settings": {
1919
"language": "Language",
2020
"sound-effects": "Sound effects",
21-
"theme": "Theme"
21+
"theme": {
22+
"title": "Theme",
23+
"errors": {
24+
"color-invalid": "Invalid color",
25+
"color-too-bright": "Color is too bright"
26+
}
27+
}
2228
},
2329
"playground": {
2430
"score": "Score: {score}"

i18n/fr.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
"settings": {
1919
"language": "Langue",
2020
"sound-effects": "Sons",
21-
"theme": "Thème"
21+
"theme": {
22+
"title": "Thème",
23+
"errors": {
24+
"color-invalid": "Couleur invalide",
25+
"color-too-bright": "Couleur trop claire"
26+
}
27+
}
2228
},
2329
"playground": {
2430
"score": "Score : {score}"

src/components/Settings.svelte

+21-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import { locale, _ } from 'svelte-i18n';
1313
1414
let _settings: Settings = loadSettings();
15-
$: errorMessage = getErrorMessage(_settings.colorTheme);
15+
$: errorMessageKey = getErrorMessageKey(_settings.colorTheme);
1616
1717
const dispatch = createEventDispatcher();
1818
@@ -32,25 +32,25 @@
3232
}
3333
};
3434
35-
const getErrorMessage = (color: string) => {
35+
const getErrorMessageKey = (color: string) => {
3636
if (!COLOR_REGEX.test(color)) {
37-
return 'Invalid color';
37+
return 'color-invalid';
3838
} else if (isTooBright(color)) {
39-
return 'Color is too bright';
39+
return 'color-too-bright';
4040
}
4141
return null;
4242
};
4343
4444
const handleInputChange = () => {
45-
if (errorMessage === null) {
45+
if (errorMessageKey === null) {
4646
setColor(_settings.colorTheme);
4747
}
4848
};
4949
5050
// handle select change event
51-
const handleLanguageChange = (newLanguage: string) => {
52-
settings.update(oldSettings => ({ ...oldSettings, language: newLanguage }));
53-
locale.set(newLanguage);
51+
const handleLanguageChange = () => {
52+
settings.update(oldSettings => ({ ...oldSettings, language: _settings.language }));
53+
locale.set(_settings.language);
5454
};
5555
5656
onMount(() => {
@@ -68,15 +68,21 @@
6868
<IconButton on:click={close} icon={IoMdClose} />
6969
</div>
7070

71+
<!-- Language -->
7172
<div class="section">
7273
<span class="section__title">{$_('settings.language')}</span>
73-
<select class="section__content" bind:value={_settings.language}>
74+
<select
75+
class="section__content"
76+
bind:value={_settings.language}
77+
on:change={handleLanguageChange}
78+
>
7479
{#each Object.entries(LANGS) as [key, value]}
75-
<option value={key} on:click={() => handleLanguageChange(key)}>{value}</option>
80+
<option value={key}>{value}</option>
7681
{/each}
7782
</select>
7883
</div>
7984

85+
<!-- Sounds -->
8086
<div class="section">
8187
<span class="section__title">{$_('settings.sound-effects')}</span>
8288
<label class="switch section__content">
@@ -85,22 +91,23 @@
8591
</label>
8692
</div>
8793

94+
<!-- Color -->
8895
<div class="section">
89-
<span class="section__title">{$_('settings.theme')}</span>
96+
<span class="section__title">{$_('settings.theme.title')}</span>
9097
<div class="colors section__content">
9198
<div class="input-container">
9299
<input
93100
type="text"
94101
class="color-input"
95102
placeholder="#353535"
96-
class:color-input--invalid={errorMessage !== null}
103+
class:color-input--invalid={errorMessageKey !== null}
97104
bind:value={_settings.colorTheme}
98105
on:input={handleInputChange}
99106
/>
100-
{#if errorMessage !== null}
107+
{#if errorMessageKey !== null}
101108
<div class="input-error">
102109
<Icon icon={MdDoNotDisturb} />
103-
{errorMessage}
110+
{$_(`settings.theme.errors.${errorMessageKey}`)}
104111
</div>
105112
{/if}
106113
</div>

0 commit comments

Comments
 (0)