Intl
Intl
is a light-weight service that provides internationalization (i18n) functionalities.
Classes
Intl
Defined in: intl.service.ts:26
The Intl
service provides i18n-related functionalities.
See
https://github.com/Modyfi/vite-plugin-yaml
Example
import { Intl } from '@spuxx/js-utils';import de from './translations/de.yml';
Intl.setup({ dictionaries: [{ locale: 'de', values: de }], fallbackLocale: 'de',});Intl.translate('foo');
Extends
any
Constructors
new Intl()
new Intl():
Intl
Returns
Inherited from
ServiceMixin<Intl>().constructor
Accessors
currentDictionary
Get Signature
get
static
currentDictionary():any
Defined in: intl.service.ts:95
Returns
any
currentLocale
Get Signature
get
static
currentLocale():any
Defined in: intl.service.ts:81
Returns
any
dictionaries
Get Signature
get
static
dictionaries():any
Defined in: intl.service.ts:88
Returns
any
fallbackLocale
Get Signature
get
static
fallbackLocale():any
Defined in: intl.service.ts:74
Returns
any
missingLocalizationPrefix
Get Signature
get
static
missingLocalizationPrefix():string
Defined in: intl.service.ts:133
Keys that cannot be translated due to missing localization will be returned and prefixed with this string.
Returns
string
Methods
setLocale()
static
setLocale(locale
):void
Defined in: intl.service.ts:59
Parameters
locale
string
Returns
void
setup()
static
setup(options
):void
Defined in: intl.service.ts:44
Sets up Intl
with the given options. Needs to be called at application startup.
Parameters
options
SetupOptions
The options to use.
Returns
void
See
https://github.com/Modyfi/vite-plugin-yaml
Example
import { Intl } from '@spuxx/js-utils';import de from './translations/de.yml';
Intl.setup({ dictionaries: [{ locale: 'de', values: de }], fallbackLocale: 'de',});
translate()
static
translate(key
,vars
?):any
Defined in: intl.service.ts:115
Translates the given key.
Parameters
key
string
The key to translate.
vars?
Record
<string
, string
>
Returns
any
The translated value.
Example
// Using the service directly:console.log(Intl.translate('foo'));// Or using the shorthand:console.log(intl('foo'));
// Using variables:console.log(Intl.translate('foo', { bar: 'baz' })); // 'Hello {bar}' -> 'Hello baz'
Interfaces
Dictionary
Defined in: intl.service.ts:4
Properties
locale
locale:
string
Defined in: intl.service.ts:5
values
values:
Record
<string
,unknown
>
Defined in: intl.service.ts:6
Variables
intl
const
intl:any
Defined in: intl.service.ts:156