@nativescript-community/l
Version:
Native internationalization plugin for NativeScript using native capabilities of each platform
32 lines • 1.06 kB
JavaScript
import { vsprintf } from 'sprintf-js';
import { Device, Utils } from '@nativescript/core';
let resources;
function getResources() {
if (!resources) {
resources = Utils.ad.getApplicationContext().getResources();
}
return resources;
}
;
export function localizeNative(key, ...args) {
let localizedString;
try {
const identifier = Utils.ad.resources.getStringId(key);
localizedString = identifier === 0 ? key : getResources().getString(identifier);
return vsprintf(localizedString, args);
}
catch (error) {
return key;
}
}
const sdkVersion = parseInt(Device.sdkVersion, 10);
export function overrideNativeLocale(lang) {
const locale = new java.util.Locale(lang);
java.util.Locale.setDefault(locale);
const resources = getResources();
const configuration = resources.getConfiguration();
configuration.locale = locale;
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
return true;
}
//# sourceMappingURL=localizenative.android.js.map