Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/core/proto_utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { EquippedItem } from './equipped_item.js';
import { Gear, ItemSwapGear } from './gear.js';
import { gemEligibleForSocket, gemMatchesSocket } from './gems.js';
import { getEligibleEnchantSlots, getEligibleItemSlots } from './utils.js';
import { getLangId } from '../../i18n/locale_service';

const dbUrlJson = '/mop/assets/database/db.json';
const dbUrlBin = '/mop/assets/database/db.bin';
Expand Down Expand Up @@ -400,7 +401,7 @@ export class Database {
return Database.getWowheadTooltipData(id, 'spell', { signal: options?.signal });
}
private static async getWowheadTooltipData(id: number, tooltipPostfix: string, options: { signal?: AbortSignal } = {}): Promise<IconData> {
const url = `https://nether.wowhead.com/mop-classic/tooltip/${tooltipPostfix}/${id}?lvl=${CHARACTER_LEVEL}&dataEnv=${WOWHEAD_EXPANSION_ENV}`;
const url = `https://nether.wowhead.com/mop-classic/tooltip/${tooltipPostfix}/${id}?lvl=${CHARACTER_LEVEL}&dataEnv=${WOWHEAD_EXPANSION_ENV}&locale=${getLangId()}`;
try {
const response = await fetch(url, { signal: options?.signal });
const json = await response.json();
Expand Down
10 changes: 10 additions & 0 deletions ui/i18n/locale_service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Locale service for WoWSims
// Single source of truth for language settings

import { getLangId as getWoWHeadLangId } from './wowhead_locale_service';

const STORAGE_KEY = 'lang';

export const supportedLanguages: Record<string, string> = {
Expand All @@ -16,6 +18,14 @@ export const getLang = (): string => {
return setLang('en');
};

export const getLangId = (): number => {
Comment thread
htve marked this conversation as resolved.
Outdated
Comment thread
htve marked this conversation as resolved.
Outdated
const storedLang = localStorage.getItem(STORAGE_KEY);
if (storedLang && storedLang in supportedLanguages) {
return getWoWHeadLangId(storedLang);
}
return 0;
};

export const setLang = (lang: string): string => {
if (lang in supportedLanguages) {
localStorage.setItem(STORAGE_KEY, lang);
Expand Down
21 changes: 21 additions & 0 deletions ui/i18n/wowhead_locale_service.ts
Comment thread
htve marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const DEFAULT_LANG_ID = 0;

//refer to Wowhead locale Ids
const LANG_ID_MAP: Record<string, number> = {
Comment thread
htve marked this conversation as resolved.
Outdated
ko: 1,
fr: 2,
de: 3,
cn: 4,
es: 6,
ru: 7,
pt: 8,
it: 9,
tw: 10,
mx: 11,
} as const;

// Map language codes to numeric Id
export const getLangId = (code: string): number => {
const normalized = code.toLowerCase();
return LANG_ID_MAP[normalized] ?? DEFAULT_LANG_ID;
};