Skip to content

Commit

Permalink
⭐ new(index): add availableLocales (related issue #193, PR #528) by @…
Browse files Browse the repository at this point in the history
…exoego

* feat(index): Fix #193 add availableLocales

* Update src/index.js

Co-Authored-By: exoego <ytatsuno.jp@gmail.com>

* feat(index): Fix #193 add type definition to availableLocales

* fix(index): add missing type definition to numberFormats

* fix(index): Fix #193 add docs to availableLocales

* Update vuepress/api/README.md

Co-Authored-By: exoego <ytatsuno.jp@gmail.com>

* fix(index): Fix #193 ensure order of locales
  • Loading branch information
exoego authored and kazupon committed Mar 8, 2019
1 parent 396c5ca commit 8f75b1f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions decls/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ declare interface I18n {
set fallbackLocale (locale: Locale): void,
get messages (): LocaleMessages,
get dateTimeFormats (): DateTimeFormats,
get availableLocales (): Locale[],
get missing (): ?MissingHandler,
set missing (handler: MissingHandler): void,
get formatter (): Formatter,
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default class VueI18n {
get messages (): LocaleMessages { return looseClone(this._getMessages()) }
get dateTimeFormats (): DateTimeFormats { return looseClone(this._getDateTimeFormats()) }
get numberFormats (): NumberFormats { return looseClone(this._getNumberFormats()) }
get availableLocales (): Locale[] { return Object.keys(this.messages).sort() }

get locale (): Locale { return this._vm.locale }
set locale (locale: Locale): void {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ describe('basic', () => {
})
})

describe('i18n#availableLocales', () => {
it('should return locales defined in messages in lexical order', () => {
assert.deepStrictEqual(i18n.availableLocales, ['en', 'ja'])
})
})

let desc = VueI18n.availabilities.dateTimeFormat ? describe : describe.skip
desc('i18n#d', () => {
let dt
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ declare class VueI18n {
readonly messages: VueI18n.LocaleMessages;
readonly dateTimeFormats: VueI18n.DateTimeFormats;
readonly numberFormats: VueI18n.NumberFormats;
readonly availableLocales: VueI18n.Locale[];

locale: VueI18n.Locale;
fallbackLocale: VueI18n.Locale;
Expand Down
12 changes: 12 additions & 0 deletions vuepress/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ The number formats of localization.

* **See also:** `NumberFormats` type of [flowtype definitions](https://github.com/kazupon/vue-i18n/blob/dev/decls/i18n.js)

#### availableLocales

> :new: 8.9.0+
* **Type:** `Locale[]`

* **Default:** `[]`

* **Examples:** `["en", "ja"]`

The list of available locales in `messages` in lexical order.

#### formatter

* **Type:** `Formatter`
Expand Down

0 comments on commit 8f75b1f

Please sign in to comment.