1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-05 02:08:14 +09:00

Revert "表示言語が設定されてない場合、ブラウザの言語と関係なく日本語にする (MisskeyIO#175)" (#28)

This reverts commit e695c60a1d.
This commit is contained in:
Cocoa Hoto 2024-06-20 07:57:33 +09:00 committed by GitHub
parent e2a3e1f04f
commit 2c481cc6c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 4 deletions

View File

@ -34,9 +34,17 @@
//#region Detect language & fetch translations //#region Detect language & fetch translations
if (!localStorage.hasOwnProperty('locale')) { if (!localStorage.hasOwnProperty('locale')) {
const supportedLangs = LANGS;
let lang = localStorage.getItem('lang'); let lang = localStorage.getItem('lang');
if (lang == null || lang.toString == null || lang.toString() === 'null') { if (lang == null || !supportedLangs.includes(lang)) {
lang = 'ja-JP'; if (supportedLangs.includes(navigator.language)) {
lang = navigator.language;
} else {
lang = supportedLangs.find(x => x.split('-')[0] === navigator.language);
// Fallback
if (lang == null) lang = 'en-US';
}
} }
const metaRes = await window.fetch('/api/meta', { const metaRes = await window.fetch('/api/meta', {
@ -59,6 +67,12 @@
return; return;
} }
// for https://github.com/misskey-dev/misskey/issues/10202
if (lang == null || lang.toString == null || lang.toString() === 'null') {
console.error('invalid lang value detected!!!', typeof lang, lang);
lang = 'en-US';
}
const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`); const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`);
if (localRes.status === 200) { if (localRes.status === 200) {
localStorage.setItem('lang', lang); localStorage.setItem('lang', lang);

View File

@ -13,7 +13,7 @@ export const hostname = address.hostname;
export const url = address.origin; export const url = address.origin;
export const apiUrl = location.origin + '/api'; export const apiUrl = location.origin + '/api';
export const wsOrigin = location.origin; export const wsOrigin = location.origin;
export const lang = miLocalStorage.getItem('lang') ?? 'ja-JP'; export const lang = miLocalStorage.getItem('lang') ?? 'en-US';
export const langs = _LANGS_; export const langs = _LANGS_;
const preParseLocale = miLocalStorage.getItem('locale'); const preParseLocale = miLocalStorage.getItem('locale');
export let locale = preParseLocale ? JSON.parse(preParseLocale) : null; export let locale = preParseLocale ? JSON.parse(preParseLocale) : null;

View File

@ -13,7 +13,7 @@ class SwLang {
public cacheName = `mk-cache-${_VERSION_}`; public cacheName = `mk-cache-${_VERSION_}`;
public lang: Promise<string> = get('lang').then(async prelang => { public lang: Promise<string> = get('lang').then(async prelang => {
if (!prelang) return 'ja-JP'; if (!prelang) return 'en-US';
return prelang; return prelang;
}); });