Skip to content

Commit

Permalink
Revert "表示言語が設定されてない場合、ブラウザの言語と関係なく日本語にする (MisskeyIO#175)"
Browse files Browse the repository at this point in the history
This reverts commit e695c60.
  • Loading branch information
Hoto-Cocoa committed Jun 19, 2024
1 parent e2a3e1f commit 3d6391e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions packages/backend/src/server/web/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@

//#region Detect language & fetch translations
if (!localStorage.hasOwnProperty('locale')) {
const supportedLangs = LANGS;
let lang = localStorage.getItem('lang');
if (lang == null || lang.toString == null || lang.toString() === 'null') {
lang = 'ja-JP';
if (lang == null || !supportedLangs.includes(lang)) {
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', {
Expand All @@ -59,6 +67,12 @@
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`);
if (localRes.status === 200) {
localStorage.setItem('lang', lang);
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const hostname = address.hostname;
export const url = address.origin;
export const apiUrl = location.origin + '/api';
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_;
const preParseLocale = miLocalStorage.getItem('locale');
export let locale = preParseLocale ? JSON.parse(preParseLocale) : null;
Expand Down
2 changes: 1 addition & 1 deletion packages/sw/src/scripts/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SwLang {
public cacheName = `mk-cache-${_VERSION_}`;

public lang: Promise<string> = get('lang').then(async prelang => {
if (!prelang) return 'ja-JP';
if (!prelang) return 'en-US';
return prelang;
});

Expand Down

0 comments on commit 3d6391e

Please sign in to comment.