UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 2.74 kB
import*as I18n from"../../third_party/i18n/i18n.js";import*as Platform from"../platform/platform.js";import*as Root from"../root/root.js";import{DevToolsLocale}from"./DevToolsLocale.js";import{BUNDLED_LOCALES as BUNDLED_LOCALES_GENERATED,DEFAULT_LOCALE,LOCAL_FETCH_PATTERN,LOCALES,REMOTE_FETCH_PATTERN}from"./locales.js";const i18nInstance=new I18n.I18n.I18n(LOCALES,DEFAULT_LOCALE),BUNDLED_LOCALES=new Set([...BUNDLED_LOCALES_GENERATED]);export function lookupClosestSupportedDevToolsLocale(e){return i18nInstance.lookupClosestSupportedLocale(e)}export function getAllSupportedDevToolsLocales(){return[...i18nInstance.supportedLocales]}function getLocaleFetchUrl(e,t){const o=Root.Runtime.getRemoteBase(t);if(o&&o.version&&!BUNDLED_LOCALES.has(e))return REMOTE_FETCH_PATTERN.replace("@HOST@","devtools://devtools").replace("@VERSION@",o.version).replace("@LOCALE@",e);const n=LOCAL_FETCH_PATTERN.replace("@LOCALE@",e);return new URL(n,import.meta.url).toString()}export async function fetchAndRegisterLocaleData(e,t=self.location.toString()){const o=fetch(getLocaleFetchUrl(e,t)).then((e=>e.json())),n=new Promise(((e,t)=>window.setTimeout((()=>t(new Error("timed out fetching locale"))),5e3))),r=await Promise.race([n,o]);i18nInstance.registerLocaleData(e,r)}export function getLazilyComputedLocalizedString(e,t,o={}){return()=>getLocalizedString(e,t,o)}export function getLocalizedString(e,t,o={}){return e.getLocalizedStringSetFor(DevToolsLocale.instance().locale).getLocalizedString(t,o)}export function registerUIStrings(e,t){return i18nInstance.registerFileStrings(e,t)}export function getFormatLocalizedString(e,t,o){const n=e.getLocalizedStringSetFor(DevToolsLocale.instance().locale).getMessageFormatterFor(t),r=document.createElement("span");for(const e of n.getAst())if(1===e.type){const t=o[e.value];t&&r.append(t)}else"value"in e&&r.append(String(e.value));return r}export function serializeUIString(e,t={}){const o={string:e,values:t};return JSON.stringify(o)}export function deserializeUIString(e){return e?JSON.parse(e):{string:"",values:{}}}export function lockedString(e){return e}export function lockedLazyString(e){return()=>e}export function getLocalizedLanguageRegion(e,t){const o=new Intl.Locale(e);Platform.DCHECK((()=>void 0!==o.language)),Platform.DCHECK((()=>void 0!==o.baseName));const n=o.language||"en",r=o.baseName||"en-US",a=n===new Intl.Locale(t.locale).language?"en":r,l=new Intl.DisplayNames([t.locale],{type:"language"}).of(n),i=new Intl.DisplayNames([a],{type:"language"}).of(n);let s="",c="";if(o.region){s=` (${new Intl.DisplayNames([t.locale],{type:"region",style:"short"}).of(o.region)})`,c=` (${new Intl.DisplayNames([a],{type:"region",style:"short"}).of(o.region)})`}return`${l}${s} - ${i}${c}`}