Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TECH] Utiliser les termes "locales" au lieu de "languages" (PIX-6772) #464

Merged
merged 6 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions components/LocaleSwitcher/LocaleSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</button>
<ul v-if="showMenu" class="locale-switcher__dropdown-menu">
<li
v-for="(option, index) in languages.menu"
v-for="(option, index) in menu"
:key="`locale-switcher-${index}`"
:class="{
'locale-switcher__dropdown-menu--active':
Expand All @@ -48,7 +48,7 @@
</button>
<locale-switcher-sub-menu
:show-sub-menu="showSubMenu"
:available-languages="option.children"
:available-locales="option.children"
:current-locale-code="currentLocaleCode"
:selected-menu="selectedMenu"
/>
Expand All @@ -73,7 +73,7 @@
</div>
<div v-else-if="type === 'only-text'">
<ul class="locale-switcher-burger-menu">
<li v-for="option in languages.menu" :key="option.key">
<li v-for="option in menu" :key="option.key">
<template v-if="option.children">
<span
v-for="child in option.children"
Expand Down Expand Up @@ -109,7 +109,7 @@
</template>

<script>
import { language } from '~/config/language'
import { localization } from '~/config/localization'
import { getAbsoluteUrlIfSwitchWebsite } from '~/services/get-absolute-url-if-switch-website'

export default {
Expand All @@ -121,19 +121,18 @@ export default {
},
},
data() {
const languages = language
return {
showMenu: false,
showSubMenu: false,
languages,
menu: localization.menu,
}
},
computed: {
currentLocaleCode() {
return this.$i18n.locale || this.$i18n.defaultLocale
},
selectedMenu() {
return this.languages.menu
return localization.menu
.flatMap((menuItem) => menuItem.children ?? menuItem)
.find((locale) => locale.localeCode === this.currentLocaleCode)
},
Expand All @@ -159,7 +158,7 @@ export default {
this.showSubMenu = false
},
getIndexUrl(menuItem) {
const locale = language.locales.find(
const locale = localization.locales.find(
(locale) => locale.code === menuItem.localeCode
)
return getAbsoluteUrlIfSwitchWebsite({
Expand Down
16 changes: 8 additions & 8 deletions components/LocaleSwitcher/LocaleSwitcherSubMenu.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<template>
<ul v-if="showSubMenu" class="locale-switcher__dropdown-menu child">
<li
v-for="availableLanguage in availableLanguages"
:key="availableLanguage.key"
v-for="availableLocale in availableLocales"
:key="availableLocale.key"
:class="{
'locale-switcher__dropdown-menu--active':
availableLanguage.localeCode === currentLocaleCode,
availableLocale.localeCode === currentLocaleCode,
}"
>
<div class="locale-switcher__locale">
<pix-link :href="getIndexUrl(availableLanguage)">
{{ $t(availableLanguage.name) }}
<pix-link :href="getIndexUrl(availableLocale)">
{{ $t(availableLocale.name) }}
</pix-link>
</div>
</li>
Expand All @@ -19,7 +19,7 @@

<script>
import { getAbsoluteUrlIfSwitchWebsite } from '~/services/get-absolute-url-if-switch-website'
import { language } from '~/config/language'
import { localization } from '~/config/localization'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On ne souhaite pas mettre un s ? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aucune idée 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plutôt pour ne pas mettre de « s », car il me semble qu'il s'agit du paramétrage de la localization, et non des différentes locales. Mais ça ne serait pas très grave avec un « s » 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai l'impression que location conviendrait mieux :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

location en français c'est « lieu », « localité », là on est dans un contexte plus large Internationalization/localization i18n/L10n https://en.wikipedia.org/wiki/Internationalization_and_localization


export default {
name: 'LocaleSwitcherSubMenu',
Expand All @@ -28,7 +28,7 @@ export default {
type: Boolean,
default: false,
},
availableLanguages: {
availableLocales: {
type: Array,
default: null,
},
Expand All @@ -43,7 +43,7 @@ export default {
},
methods: {
getIndexUrl(menuItem) {
const locale = language.locales.find(
const locale = localization.locales.find(
(locale) => locale.code === menuItem.localeCode
)
return getAbsoluteUrlIfSwitchWebsite({
Expand Down
7 changes: 0 additions & 7 deletions config/language/index.js

This file was deleted.

7 changes: 7 additions & 0 deletions config/localization/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { config } from '../environment'
import { localization as localizationForPixSite } from './pix-site'
import { localization as localizationForPixPro } from './pix-pro'

export const localization = config.isPixSite
? localizationForPixSite
: localizationForPixPro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const availableLocales = [
domain: config.domain.french,
},
]
export const language = {
export const localization = {
menu: [
{
name: 'international',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const availableLocales = [
},
]

export const language = {
export const localization = {
menu: [
{
name: 'international',
Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { transports } from 'winston'
import routes from './services/get-routes-to-generate'
import { filterNuxtPages } from './services/filter-nuxt-pages'
import { language } from './config/language'
import { localization } from './config/localization'
import { config } from './config/environment'
import { SITES_PRISMIC_TAGS } from './services/available-sites'

Expand Down Expand Up @@ -103,7 +103,7 @@ const nuxtConfig = {

i18n: {
detectBrowserLanguage: false,
locales: language.localesForCurrentSite,
locales: localization.localesForCurrentSite,
lazy: true,
langDir: 'translations/',
...(config.isFrenchDomain
Expand Down
6 changes: 3 additions & 3 deletions pages/pix-site/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
</template>

<script>
import { language } from '~/config/language'
import { localization } from '~/config/localization'

export default {
layout: 'empty',
nuxtI18n: false,
data() {
return {
locales: language.locales,
locales: localization.locales,
shouldDisplayLocaleChoice: false,
}
},
Expand All @@ -48,7 +48,7 @@ export default {

const chosenLocale = localeCookie.split('=')[1]

const currentLocales = language.localesForCurrentSite.map(
const currentLocales = localization.localesForCurrentSite.map(
({ code }) => code
)
if (!currentLocales.includes(chosenLocale)) return null
Expand Down
6 changes: 4 additions & 2 deletions services/get-routes-to-generate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Prismic from '@prismicio/client'
import { language } from '../config/language'
import { localization } from '../config/localization'
import { config } from '../config/environment'
import { linkResolver } from '../services/link-resolver'

Expand Down Expand Up @@ -30,7 +30,9 @@ async function getRoutesInPage(api, page) {
}
)

const localesToBuild = language.localesForCurrentSite.map(({ code }) => code)
const localesToBuild = localization.localesForCurrentSite.map(
({ code }) => code
)
const routes = results
.filter(({ uid }) => Boolean(uid))
.filter(({ lang }) => localesToBuild.includes(lang))
Expand Down
51 changes: 0 additions & 51 deletions tests/config/language/index.test.js

This file was deleted.

53 changes: 53 additions & 0 deletions tests/config/localization/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
describe('#localization', () => {
let config, localizationForPixSite, localizationForPixPro
beforeEach(() => {
jest.resetModules()
config = require('~/config/environment').config
localizationForPixSite =
require('~/config/localization/pix-site').localization
localizationForPixPro =
require('~/config/localization/pix-pro').localization

jest.mock('~/config/environment', () => {
return {
config: {
isPixSite: false,
},
}
})

jest.mock('~/config/localization/pix-site', () => {
return { localization: Symbol('pix-site localization') }
})

jest.mock('~/config/localization/pix-pro', () => {
return { localization: Symbol('pix-pro localization') }
})
})

describe('when it is pix site', () => {
it('should return localization menu and locales dependant of site', () => {
// given
config.isPixSite = true

// when
const { localization } = require('~/config/localization')

// then
expect(localization).toEqual(localizationForPixSite)
})
})

describe('when it is pix pro', () => {
it('should return localization menu and locales dependant of site', () => {
// given
config.isPixSite = false

// when
const { localization } = require('~/config/localization')

// then
expect(localization).toEqual(localizationForPixPro)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getLocalesForCurrentSite, language } from '~/config/language/pix-pro'
import {
getLocalesForCurrentSite,
localization,
} from '~/config/localization/pix-pro'
import { config } from '~/config/environment'

jest.mock('~/config/environment', () => {
Expand Down Expand Up @@ -49,7 +52,7 @@ describe('#getLocalesForCurrentSite', () => {
})
})

describe('#language', () => {
describe('#localization', () => {
it('should return all menu entries for pix-pro', () => {
// given
const expectedResult = [
Expand Down Expand Up @@ -81,6 +84,6 @@ describe('#language', () => {
]

// when & then
expect(language.menu).toEqual(expectedResult)
expect(localization.menu).toEqual(expectedResult)
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getLocalesForCurrentSite, language } from '~/config/language/pix-site'
import {
getLocalesForCurrentSite,
localization,
} from '~/config/localization/pix-site'
import { config } from '~/config/environment'

jest.mock('~/config/environment', () => {
Expand Down Expand Up @@ -48,7 +51,7 @@ describe('#getLocalesForCurrentSite', () => {
})
})

describe('#language', () => {
describe('#localization', () => {
it('should return all menu entries for pix-site', () => {
// given
const expectedResult = [
Expand Down Expand Up @@ -86,6 +89,6 @@ describe('#language', () => {
]

// when & then
expect(language.menu).toEqual(expectedResult)
expect(localization.menu).toEqual(expectedResult)
})
})
6 changes: 3 additions & 3 deletions tests/services/get-routes-to-generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jest.mock('~/config/environment', () => {
},
}
})
jest.mock('~/config/language', () => {
jest.mock('~/config/localization', () => {
return {
language: {
localization: {
localesForCurrentSite: [{ code: 'fr-fr' }],
},
}
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('#getRoutesToGenerate', () => {
expect(result).toEqual(expected)
})

test('it should filter unhandled languages', async () => {
test('it should filter unhandled locales', async () => {
// Given
const expected = ['/route-to-generate']
const prismicApi = {
Expand Down