Skip to content

Commit ae4a2a4

Browse files
committed
resolved the lng change issues in japanese
1 parent b19803b commit ae4a2a4

File tree

10 files changed

+183
-179
lines changed

10 files changed

+183
-179
lines changed

js/__tests__/languagebox.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe("LanguageBox Class", () => {
138138

139139
languageBox.ja_onclick();
140140

141-
expect(languageBox._language).toBe("ja");
141+
expect(languageBox._language).toBe("ja-kanji");
142142
expect(mockActivity.storage.kanaPreference).toBe("kanji");
143143
expect(hideSpy).toHaveBeenCalled();
144144
});
@@ -148,7 +148,7 @@ describe("LanguageBox Class", () => {
148148

149149
languageBox.kana_onclick();
150150

151-
expect(languageBox._language).toBe("ja");
151+
expect(languageBox._language).toBe("ja-kana");
152152
expect(mockActivity.storage.kanaPreference).toBe("kana");
153153
expect(hideSpy).toHaveBeenCalled();
154154
});

js/activity.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class Activity {
310310
let lang = "en";
311311
if (this.storage.languagePreference !== undefined) {
312312
lang = this.storage.languagePreference;
313+
if (lang.startsWith("ja")) lang = "ja"; // normalize Japanese
313314
i18next.changeLanguage(lang);
314315
} else {
315316
lang = navigator.language;

js/languagebox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ class LanguageBox {
5959
* @returns {void}
6060
*/
6161
ja_onclick() {
62-
this._language = "ja";
63-
this.activity.storage.kanaPreference = "kanji";
64-
this.hide();
62+
this._language = "ja-kanji";
63+
this.activity.storage.kanaPreference = "kanji";
64+
this.hide();
6565
}
6666

6767
kana_onclick() {
68-
this._language = "ja";
68+
this._language = "ja-kana";
6969
this.activity.storage.kanaPreference = "kana";
7070
this.hide();
7171
}

js/turtleactions/__tests__/DrumActions.test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ describe("setupDrumActions", () => {
173173
});
174174

175175
const actionConfigs = [
176-
['setDrum', '_setdrum_0', true],
177-
['mapPitchToDrum', '_mapdrum_0', false],
176+
["setDrum", "_setdrum_0", true],
177+
["mapPitchToDrum", "_mapdrum_0", false],
178178
];
179179
describe.each(actionConfigs)("%s", (actionName, prefix, resetPitchDrumTable) => {
180180
beforeEach(() => {
@@ -186,37 +186,37 @@ describe("setupDrumActions", () => {
186186
global.Mouse.getMouseFromTurtle.mockReturnValue(null);
187187
});
188188

189-
it('sets drum style and listener', () => {
189+
it("sets drum style and listener", () => {
190190
Singer.DrumActions[actionName]("d1", 0, 1);
191-
expect(targetTurtle.singer.drumStyle).toContain('drum1');
191+
expect(targetTurtle.singer.drumStyle).toContain("drum1");
192192
expect(activity.logo.setDispatchBlock).toHaveBeenCalledWith(1, 0, prefix);
193193
expect(activity.logo.setTurtleListener).toHaveBeenCalledWith(0, prefix, expect.any(Function));
194194
});
195195

196-
it('handles MusicBlocks.isRun case', () => {
196+
it("handles MusicBlocks.isRun case", () => {
197197
const mockMouse = { MB: { listeners: [] } };
198198
global.MusicBlocks.isRun = true;
199199
global.Mouse.getMouseFromTurtle.mockReturnValue(mockMouse);
200-
Singer.DrumActions[actionName]('d1', 0);
201-
expect(targetTurtle.singer.drumStyle).toContain('drum1');
200+
Singer.DrumActions[actionName]("d1", 0);
201+
expect(targetTurtle.singer.drumStyle).toContain("drum1");
202202
expect(mockMouse.MB.listeners).toContain(prefix);
203203
});
204204

205-
it('handles direct drum name input', () => {
206-
Singer.DrumActions[actionName]('drum2', 0, 1);
207-
expect(targetTurtle.singer.drumStyle).toContain('drum2');
205+
it("handles direct drum name input", () => {
206+
Singer.DrumActions[actionName]("drum2", 0, 1);
207+
expect(targetTurtle.singer.drumStyle).toContain("drum2");
208208
});
209209

210-
it('handles rhythm ruler', () => {
210+
it("handles rhythm ruler", () => {
211211
activity.logo.inRhythmRuler = true;
212-
Singer.DrumActions[actionName]('d1', 0, 1);
212+
Singer.DrumActions[actionName]("d1", 0, 1);
213213
expect(activity.logo._currentDrumBlock).toBe(1);
214214
expect(activity.logo.rhythmRuler.Drums).toContain(1);
215215
expect(activity.logo.rhythmRuler.Rulers).toHaveLength(1);
216216
});
217217

218-
it('removes drumStyle on listener', () => {
219-
Singer.DrumActions[actionName]('d1', 0, 1);
218+
it("removes drumStyle on listener", () => {
219+
Singer.DrumActions[actionName]("d1", 0, 1);
220220
const listenerFn = activity.logo.setTurtleListener.mock.calls[0][2];
221221
listenerFn();
222222
expect(targetTurtle.singer.drumStyle).toHaveLength(0);
@@ -225,8 +225,8 @@ describe("setupDrumActions", () => {
225225
}
226226
});
227227

228-
it('only adds listener when blk undefined and not running', () => {
229-
Singer.DrumActions[actionName]('d1', 0);
228+
it("only adds listener when blk undefined and not running", () => {
229+
Singer.DrumActions[actionName]("d1", 0);
230230
expect(activity.logo.setDispatchBlock).not.toHaveBeenCalled();
231231
expect(global.Mouse.getMouseFromTurtle).not.toHaveBeenCalled();
232232
expect(activity.logo.setTurtleListener).toHaveBeenCalledWith(
@@ -236,10 +236,10 @@ describe("setupDrumActions", () => {
236236
);
237237
});
238238

239-
it('skips mouse listener when isRun and mouse null', () => {
239+
it("skips mouse listener when isRun and mouse null", () => {
240240
global.MusicBlocks.isRun = true;
241241
global.Mouse.getMouseFromTurtle.mockReturnValue(null);
242-
Singer.DrumActions[actionName]('d1', 0);
242+
Singer.DrumActions[actionName]("d1", 0);
243243
expect(activity.logo.setDispatchBlock).not.toHaveBeenCalled();
244244
expect(global.Mouse.getMouseFromTurtle).toHaveBeenCalledWith(expect.any(Object));
245245
expect(activity.logo.setTurtleListener).toHaveBeenCalledWith(

js/turtleactions/__tests__/MeterActions.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ describe("setupMeterActions", () => {
138138
[5000,0.25, ["maximum 1/4 beats per minute is 1000"], 1000, 1],
139139
])(
140140
"setBPM(%i) should handle %s range", (bpm, factor, errors, expected, errBlk) => {
141-
activity.errorMsg.mockClear();
142-
Singer.MeterActions.setBPM(bpm, factor, 0, errBlk);
143-
if (errors.length) {
144-
errors.forEach(msg => expect(activity.errorMsg).toHaveBeenCalledWith(msg, errBlk));
145-
}
146-
expect(targetTurtle.singer.bpm).toContain(expected);
147-
});
141+
activity.errorMsg.mockClear();
142+
Singer.MeterActions.setBPM(bpm, factor, 0, errBlk);
143+
if (errors.length) {
144+
errors.forEach(msg => expect(activity.errorMsg).toHaveBeenCalledWith(msg, errBlk));
145+
}
146+
expect(targetTurtle.singer.bpm).toContain(expected);
147+
});
148148
});
149149

150150
describe("master BPM settings", () => {
@@ -155,14 +155,14 @@ describe("setupMeterActions", () => {
155155
[5000,["maximum 1/4 beats per minute is 1000"], 1000],
156156
])(
157157
"setMasterBPM(%i) should result in masterBPM %i", (bpm, errors, expected) => {
158-
activity.errorMsg.mockClear();
159-
Singer.MeterActions.setMasterBPM(bpm, 0.25, 1);
160-
if (errors.length) {
161-
errors.forEach(msg => expect(activity.errorMsg).toHaveBeenCalledWith(msg, 1));
162-
}
163-
expect(Singer.masterBPM).toBe(expected);
164-
if (!errors.length) expect(Singer.defaultBPMFactor).toBe(TONEBPM / expected);
165-
});
158+
activity.errorMsg.mockClear();
159+
Singer.MeterActions.setMasterBPM(bpm, 0.25, 1);
160+
if (errors.length) {
161+
errors.forEach(msg => expect(activity.errorMsg).toHaveBeenCalledWith(msg, 1));
162+
}
163+
expect(Singer.masterBPM).toBe(expected);
164+
if (!errors.length) expect(Singer.defaultBPMFactor).toBe(TONEBPM / expected);
165+
});
166166
});
167167

168168
it("should set a listener for every beat", () => {
@@ -354,7 +354,7 @@ describe("setupMeterActions", () => {
354354
test.each([
355355
[null],
356356
[0]
357-
])('should return 0 when noteValue is %p', (noteValue) => {
357+
])("should return 0 when noteValue is %p", (noteValue) => {
358358
const result = Singer.MeterActions.getNotesPlayed(noteValue, 0);
359359
expect(result).toBe(0);
360360
});
@@ -396,7 +396,7 @@ describe("setupMeterActions", () => {
396396
});
397397

398398
it("should calculate measure count correctly", () => {
399-
targetTurtle.singer.notesPlayed = [9, 1];
399+
targetTurtle.singer.notesPlayed = [9, 1];
400400
targetTurtle.singer.pickup = 1;
401401
targetTurtle.singer.noteValuePerBeat = 1;
402402
targetTurtle.singer.beatsPerMeasure = 4;
@@ -408,7 +408,7 @@ describe("setupMeterActions", () => {
408408
test.each([
409409
[[], 80, 80],
410410
[[80, 120], undefined, 120]
411-
])('getBPM with singer.bpm %p and masterBPM %p returns %p', (bpmArray, _, expected) => {
411+
])("getBPM with singer.bpm %p and masterBPM %p returns %p", (bpmArray, _, expected) => {
412412
targetTurtle.singer.bpm = bpmArray;
413413
Singer.masterBPM = 80;
414414
const result = Singer.MeterActions.getBPM(0);
@@ -440,9 +440,9 @@ describe("setupMeterActions", () => {
440440
});
441441

442442
test.each([
443-
[0, 1/4, 'beatsPerMeasure', 4],
444-
[4, 0, 'noteValuePerBeat', 4]
445-
])('setMeter(%p, %p) defaults %s to %i', (beats, noteValue, prop, expected) => {
443+
[0, 1/4, "beatsPerMeasure", 4],
444+
[4, 0, "noteValuePerBeat", 4]
445+
])("setMeter(%p, %p) defaults %s to %i", (beats, noteValue, prop, expected) => {
446446
Singer.MeterActions.setMeter(beats, noteValue, 0);
447447
expect(targetTurtle.singer[prop]).toBe(expected);
448448
});

0 commit comments

Comments
 (0)