Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow embeds to set appLanguage #4

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions src/livecodes/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4091,8 +4091,9 @@ const configureToolsPane = (
};

const loadI18n = async (appLanguage: AppLanguage | undefined) => {
const userLang = appLanguage || (navigator.language as AppLanguage);
if (isEmbed || !userLang || userLang.toLowerCase().startsWith('en')) return;
const userLang =
appLanguage && appLanguage !== 'auto' ? appLanguage : (navigator.language as AppLanguage);
if ((isEmbed && !appLanguage) || !userLang || userLang.toLowerCase().startsWith('en')) return;

setConfig({ ...getConfig(), appLanguage: userLang });
const i18nModule: typeof import('./i18n/i18n') = await import(baseUrl + '{{hash:i18n.js}}');
Expand Down
2 changes: 1 addition & 1 deletion src/livecodes/i18n/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export const dispatchTranslationEvent = (elem: HTMLElement) => {
};

export const localizedAppLanguage: {
[key in AppLanguage]: string;
[key in Exclude<AppLanguage, 'auto'>]: string;
} = {
en: 'English',
'zh-CN': '中文(简体)',
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ export interface BlocklyContent {
js?: string;
}

export type AppLanguage = 'en' | 'ar' | 'zh-CN';
export type AppLanguage = 'auto' | 'en' | 'ar' | 'zh-CN';

export interface User {
uid: string;
Expand Down
Loading