Skip to content

Commit

Permalink
Remove configuration of locale via JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
romaricpascal committed Oct 3, 2022
1 parent 44bfc76 commit cead23d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
3 changes: 1 addition & 2 deletions src/govuk/components/character-count/character-count.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ function CharacterCount ($module, config) {
datasetConfig
)

console.log(this.$module)
this.i18n = new I18n(extractConfigByNamespace(this.config, 'i18n'), {
// Read the fallback if necessary rather than have it set in the defaults
locale: this.config.i18nLocale || closestAttributeValue($module, 'lang')
locale: closestAttributeValue($module, 'lang')
})

// Determine the limit attribute (characters or words)
Expand Down
34 changes: 0 additions & 34 deletions src/govuk/components/character-count/character-count.unit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ describe('CharacterCount', () => {
// Other keys remain untouched
expect(component.formatCountMessage(10, 'characters')).toEqual('You have 10 characters remaining')
})

it('overrides the default locale', () => {
const component = new CharacterCount(createElement('div'), {
i18nLocale: 'de'
})
expect(component.formatCountMessage(10000, 'words')).toEqual('You have 10.000 words remaining')
})
})

describe('lang attribute configuration', () => {
Expand Down Expand Up @@ -102,13 +95,6 @@ describe('CharacterCount', () => {
expect(component.formatCountMessage(10, 'characters')).toEqual('You have 10 characters remaining')
})

it('overrides the default locale', () => {
const component = new CharacterCount(createElement('div', {
'data-i18n-locale': 'de'
}))
expect(component.formatCountMessage(10000, 'words')).toEqual('You have 10.000 words remaining')
})

describe('precedence over JavaScript configuration', () => {
it('overrides translation keys', () => {
const $div = createElement('div', { 'data-i18n.characters-under-limit-one': 'Custom text. Count: %{count}' })
Expand All @@ -121,26 +107,6 @@ describe('CharacterCount', () => {
// Other keys remain untouched
expect(component.formatCountMessage(10, 'characters')).toEqual('You have 10 characters remaining')
})

it('overrides the default locale', () => {
const $div = createElement('div', {
'data-i18n-locale': 'de' // Dot as thousand separator
})
const component = new CharacterCount($div, {
i18nLocale: 'fr' // Space as thousand separator
})
expect(component.formatCountMessage(10000, 'words')).toEqual('You have 10.000 words remaining')
})

it('overrides the locale in lang attribute', () => {
const $div = createElement('div', {
'data-i18n-locale': 'de',
lang: 'fr'
})
const component = new CharacterCount($div)

expect(component.formatCountMessage(10000, 'words')).toEqual('You have 10.000 words remaining')
})
})
})
})
Expand Down

0 comments on commit cead23d

Please sign in to comment.