@jupyterlite/translation
Advanced tools
Comparing version 0.1.0-alpha.9 to 0.1.0-alpha.10
@@ -12,2 +12,3 @@ import { JSONObject } from '@lumino/coreutils'; | ||
get(locale: string): Promise<JSONObject>; | ||
private _prevLocale; | ||
} |
import { PageConfig, URLExt } from '@jupyterlab/coreutils'; | ||
/** | ||
* A fake locale to retrieve all the language packs. | ||
*/ | ||
const ALL = 'all'; | ||
/** | ||
* A class to handle requests to /api/translations | ||
*/ | ||
export class Translation { | ||
constructor() { | ||
this._prevLocale = ''; | ||
} | ||
/** | ||
@@ -13,6 +20,34 @@ * Get the translation data for the given locale | ||
const apiURL = URLExt.join(PageConfig.getBaseUrl(), `api/translations/${locale}.json`); | ||
const response = await fetch(apiURL); | ||
const json = JSON.parse(await response.text()); | ||
return json; | ||
try { | ||
const response = await fetch(apiURL); | ||
const json = JSON.parse(await response.text()); | ||
if (this._prevLocale !== ALL && locale === ALL) { | ||
// TODO: fix this logic upstream? | ||
// the upstream translation plugin relies on the comparison between | ||
// the display name and the native name to enable or disable the commands: | ||
// https://github.com/jupyterlab/jupyterlab/blob/befa831ffef36321b87f352a48fbe2439df6c872/packages/translation-extension/src/index.ts#L117 | ||
const prev = this._prevLocale; | ||
json.data[prev].displayName = json.data[prev].nativeName; | ||
if (prev !== 'en') { | ||
json.data['en'].displayName = `${json.data['en'].nativeName} (default)`; | ||
} | ||
} | ||
this._prevLocale = locale; | ||
return json; | ||
} | ||
catch (e) { | ||
if (locale) { | ||
return { | ||
data: {}, | ||
message: `Language pack '${locale}' not installed!` | ||
}; | ||
} | ||
return { | ||
data: { | ||
en: { displayName: 'English', nativeName: 'English' } | ||
}, | ||
message: '' | ||
}; | ||
} | ||
} | ||
} |
{ | ||
"name": "@jupyterlite/translation", | ||
"version": "0.1.0-alpha.9", | ||
"version": "0.1.0-alpha.10", | ||
"description": "JupyterLite - Translation", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/jupyterlite/jupyterlite", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5461
107