Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { FluentBundle, FluentDateTime, FluentError, FluentNumber, FluentResource, Scope } from '@fluent/bundle';
import * as compat from '@fluent/bundle/compat';
// FluentBundle examples:
const bundle = new FluentBundle(['en-US']);
const compatBundle = new compat.FluentBundle(['en-US']);
// FluentResource examples:
const resource = new FluentResource(`test=Some other message with args arg1={$arg1} and arg2={$arg2}`);
bundle.addResource(resource, { allowOverrides: true });
const msg = bundle.getMessage('test');
if (msg && msg.value) {
const args = {
$arg1: "#1",
$arg2: "#2"
};
const errors: Error[] = [];
const formatted: string = bundle.formatPattern(msg.value, args, errors);
console.log(formatted);
}
// Fluent type examples:
const num = new FluentNumber(6);
const err = new FluentError('argh');
const dt = new FluentDateTime(new Date(2000, 0, 1));
["Runtime", new Subject("Runtime", () => new FluentResource(ftl))],
]);
return 'LT'
}
},
STR ([n]: FluentValue[]) {
return n.value.toString()
},
MAYBE_HAS ([n]: FluentValue>[]) {
return maybeHas(n.value) ? 'has' : 'none'
}
}
for (const locale of Object.keys(LangMap)) {
const bundle = new FluentBundle(locale, {
functions
})
bundle.addResource(new FluentResource(LangMap[locale]))
BundleMap[locale] = bundle
}
const langs = [chrome.i18n.getUILanguage(), ...Langs]
const bundles = langs.map(i => BundleMap[i]).filter(Boolean)
export const LocalizationProvider: React.FC = ({ children }) => {
return
<>{children}
}
async function fetchResource(locale, id) {
const url = id.replace("{locale}", locale);
const response = await fetch(url);
return new FluentResource(await response.text());
}