Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import { normalizeLanguage } from './language.js';
|
||||
|
||||
// 与后端 setting/language_setting 的 Normalize 共用同一份用例,防止两端归一化口径漂移
|
||||
const sharedCases = JSON.parse(
|
||||
readFileSync(new URL('./language_cases.json', import.meta.url), 'utf8'),
|
||||
);
|
||||
|
||||
test('shared normalization cases (kept in sync with backend)', () => {
|
||||
for (const { input, expected } of sharedCases) {
|
||||
assert.equal(normalizeLanguage(input), expected, input);
|
||||
}
|
||||
});
|
||||
|
||||
test('traditional Chinese variants map to zh-TW', () => {
|
||||
for (const lng of [
|
||||
'zh-TW',
|
||||
'zh-HK',
|
||||
'zh-MO',
|
||||
'zh-Hant',
|
||||
'zh-Hant-TW',
|
||||
'zh_TW',
|
||||
]) {
|
||||
assert.equal(normalizeLanguage(lng), 'zh-TW', lng);
|
||||
}
|
||||
});
|
||||
|
||||
test('simplified Chinese variants map to zh', () => {
|
||||
for (const lng of [
|
||||
'zh',
|
||||
'zh-CN',
|
||||
'zh-SG',
|
||||
'zh-Hans',
|
||||
'zh-Hans-HK',
|
||||
undefined,
|
||||
'',
|
||||
]) {
|
||||
assert.equal(normalizeLanguage(lng), 'zh', String(lng));
|
||||
}
|
||||
});
|
||||
|
||||
test('other languages keep only the primary subtag', () => {
|
||||
assert.equal(normalizeLanguage('en-US'), 'en');
|
||||
assert.equal(normalizeLanguage('ja-JP'), 'ja');
|
||||
assert.equal(normalizeLanguage('vi'), 'vi');
|
||||
assert.equal(normalizeLanguage('ko-KR'), 'ko');
|
||||
});
|
||||
Reference in New Issue
Block a user