fix: localize default custom mode text (@Positiveoo1)#8193
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes custom-mode default text localization: when the stored custom text is still the untouched default, the generated word list now comes from the currently selected language; user-entered custom text remains unchanged.
Changes:
- Pass
language.wordsinto custom-text retrieval for custom mode word generation. - Add “untouched default” detection in
CustomText.getText(languageWords?)to substitute language words. - Add Vitest coverage for default-vs-user-custom behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| frontend/src/ts/test/words-generator.ts | Uses language word list for custom mode when custom text is default. |
| frontend/src/ts/test/custom-text.ts | Adds default-text detection + optional localization behavior in getText. |
| frontend/tests/test/custom-text.spec.ts | Tests default localization + preserving user custom text. |
| export function getText(languageWords?: string[]): string[] { | ||
| const text = customTextSettings.get().text; | ||
| if (languageWords !== undefined && isDefaultCustomText(text)) { | ||
| return languageWords.slice(0, text.length); | ||
| } | ||
| return text; |
| function isDefaultCustomText(text: string[]): boolean { | ||
| return ( | ||
| text.length === defaultCustomText.length && | ||
| text.every((word, index) => word === defaultCustomText[index]) | ||
| ); | ||
| } | ||
|
|
||
| export function getText(languageWords?: string[]): string[] { | ||
| const text = customTextSettings.get().text; | ||
| if (languageWords !== undefined && isDefaultCustomText(text)) { | ||
| return languageWords.slice(0, text.length); | ||
| } |
8761105 to
545f08c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
frontend/src/ts/test/custom-text.ts:104
userEditedSettingsTextis set unconditionally insetText. Several code paths callCustomText.setText(...)without the user actually changing the text (eg URL settings loader, challenges, and the Custom Text modal save flow). That permanently flips the flag and will stopgetEffectiveTextfrom localizing the untouched default in those scenarios, so the issue can still reproduce after any such flow.
Consider decoupling the flag from setText (eg add setText(txt, { markUserEdited: boolean }) / setTextFromUserInput, or only set the flag from the UI when the text field is dirty).
export function setText(txt: string[]): void {
const currentSettings = customTextSettings.get();
userEditedSettingsText.set(true);
customTextSettings.set({
...currentSettings,
text: txt,
limit: { value: txt.length, mode: currentSettings.limit.mode },
});
| const defaultCustomTextSettings: CustomTextSettings = { | ||
| text: ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"], | ||
| text: defaultCustomText, | ||
| mode: "repeat", | ||
| limit: { value: 9, mode: "word" }, | ||
| pipeDelimiter: false, |
545f08c to
93c3173
Compare
|
hi @Positiveoo1, thank you for your contribution. I wouldn't say this is an issue to fix. The custom mode doesnt really have a language. The default text "the quick brown fox" is just a placeholder. Once you defined a custom text you'll never see it again. We could think about removing the language from the custom text
@Miodec what do you think? |
Fixes #8192.
Custom mode now uses words from the selected language when the custom text is still the untouched default. User-entered custom text is preserved and does not change when switching languages.