-
Notifications
You must be signed in to change notification settings - Fork 0
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
Initial version of localization #12
Conversation
c4f53ef
to
241820a
Compare
0b9c2bf
to
7d46879
Compare
|
||
Aja yksikkötestit komennolla: | ||
|
||
`npm test` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`npm test` | |
`npm run test` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ei tarvi, npm test toimii
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tämä on varmaan ainoa npm-skriptin ajava komento, jossa ei ole pakko laittaa run
. Yhdenmukaisuus on hyve tässäkin, vaikka node ei olisikaan yhdenmukainen.
README.md
Outdated
|
||
Aja sen jälkeen testit komennolla: | ||
|
||
`npm run test:ui` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En näe kauheasti järkeä siinä, että meillä on tällainen "test:ui"-skripti. Tuo vain piilottaa sen, että siellä on Playwright taustalla ja hankaloittaa parametrien syöttämistä. Jos haluaa kutsua sitä parametrisoituna, niin miksei sitten vain käytetä komentoa npx playwright test
?
README.md
Outdated
|
||
`npm test` | ||
|
||
### E2E-testit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mun mielestä näiden kutsuminen E2E-testeiksi on aika kyseenalaista, kun näissä kuitenkin mockataan käytännössä kaikki rajapinnat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vaihdan tuon kälitesteiksi, mut on tossa kuitenkin vähän e2e testiä siinä mielessä et siel on omakin apinsa (ainakin uusi lokalisointi).
src/app/lokalisaatio/fi.json
Outdated
{ | ||
"title": "Valintojen toteuttaminen", | ||
"julkaistu": "Julkaistu", | ||
"arkistoitu": "Arkistoitu", | ||
"common": { | ||
"name": "Nimi", | ||
"status": "Tila", | ||
"choose": "Valitse...", | ||
"spring": "kevät", | ||
"autumn": "syksy", | ||
"noresults": "Ei hakutuloksia", | ||
"perpage": "Näytä per sivu:" | ||
}, | ||
"error": { | ||
"server": "Palvelinpyyntö epäonnistui!", | ||
"code": "Virhekoodi: ", | ||
"retry": "Yritä uudelleen", | ||
"unknown": "Jokin meni vikaan" | ||
}, | ||
"haku": { | ||
"title": "Haut", | ||
"hakutapa": "Hakutapa", | ||
"alkamiskausi": "Koulutuksen alkamiskausi", | ||
"hakukohteet": "Hakukohteet", | ||
"search": "Hae hakuja", | ||
"amount": "Hakuja:" | ||
}, | ||
"hakukohde": { | ||
"valitse": "Valitse hakukohde", | ||
"oid": "Hakukohde oid: " | ||
}, | ||
"perustiedot": { | ||
"title": "Perustiedot" | ||
}, | ||
"hakeneet": { | ||
"title": "Hakeneet" | ||
}, | ||
"valinnanhallinta": { | ||
"title": "Valinnan hallinta" | ||
}, | ||
"koekutsut": { | ||
"title": "Valintakoekutsut" | ||
}, | ||
"pistesyotto": { | ||
"title": "Pistesyöttö" | ||
}, | ||
"harkinnanvaraiset": { | ||
"title": "Harkinnanvaraiset" | ||
}, | ||
"hakijaryhmat": { | ||
"title": "Hakijaryhmät" | ||
}, | ||
"valintalaskennantulos": { | ||
"title": "Valintalaskennan tulos" | ||
}, | ||
"sijoitteluntulokset": { | ||
"title": "Sijoittelun tulokset" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tän vois kyllä miettiä, että halutaanko avainten olevan tällaista suomi-englanti-sekasotkua, ja jos kyllä, niin millä logiikalla.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mennään pelkästään suomella avaimisissa, ei ruveta kääntämään englanniksi niitä
import { FullSpinner } from './components/full-spinner'; | ||
import { useAsiointiKieli } from './hooks/useAsiointiKieli'; | ||
import { createLocalization } from './lib/localization/localizations'; | ||
|
||
const localization = createLocalization(); | ||
|
||
export default function Wrapper({ children }: { children: React.ReactNode }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tän vois varmaan nimetä uudelleen LocalizationProvider
:ksi tms.
export const makeKoulutuksenAlkamiskausiColumn = (): Column<Haku> => ({ | ||
title: 'Koulutuksen alkamiskausi', | ||
export const makeKoulutuksenAlkamiskausiColumn = ( | ||
t: (s: string) => string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { TFunction } from "react-i18next";
t: (s: string) => string, | |
t: TFunction, |
src/app/hooks/useAsiointiKieli.ts
Outdated
import { Language } from '../lib/localization/localization-types'; | ||
|
||
export const getAsiointiKieli = () => { | ||
return client.get(configuration.asiointiKieliUrl); | ||
export const getAsiointiKieli = async (): Promise<Language> => { | ||
const response = await client.get(configuration.asiointiKieliUrl); | ||
return response.data ?? 'fi'; | ||
}; | ||
|
||
export const useAsiointiKieli = () => | ||
useQuery({ | ||
queryKey: ['getAsiointiKieli'], | ||
queryFn: getAsiointiKieli, | ||
|
||
staleTime: Infinity, | ||
}); | ||
|
||
export const useUserLanguage = (): Language => { | ||
const { data } = useAsiointiKieli(); | ||
return data || 'fi'; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Näitä muutoksia ei varmaankaan tarvita. useAsiointiKieli-hookkia ei pitäisi tarvita käyttää muualla kuin Wrapper-komponentissa, koska asiointikieli asetetaan i18nextiin jo ennen kuin mitään muuta renderöidään -> voidaan siis käyttää i18nextin kieltä. Olisi myös ehkä parempi tehdä oma useTranslation
-hook, joka palauttaa myös translateName
:n, jolle olisi jo annettu i18nextin kieli. Näin komponenteissa ei tarvitsisi ensin hakea kieltä ja sitten kutsua sillä translateName:a.
Kielen saa i18nextistä näin:
const { i18n } = useTranslation();
const { language } = i18n;
|
||
export const createLocalization = () => { | ||
i18n | ||
.use(HttpBackend) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ehkä vois käyttää ennemmin tätä? https://github.com/dotcore64/i18next-fetch-backend
src/app/lokalisaatio/route.ts
Outdated
} | ||
|
||
function getTranslationsFromFile(lng: string) { | ||
console.log('getTranslationsFromFile ' + lng); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log('getTranslationsFromFile ' + lng); |
src/app/lokalisaatio/route.ts
Outdated
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const lng = searchParams.get('lng') || 'fi'; | ||
if (!isProd && isDev && isLocalhost) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jos isDev
, niin silloin myös aina !isProd
.
if (!isProd && isDev && isLocalhost) { | |
if (isDev && isLocalhost) { |
337c3b7
to
f76b854
Compare
Oletko lisännyt tarvittavat yksikkö- tai ui-testit toiminnallisuudelle? Kyllä
Oletko tarkistanut ja päivittänyt riippuvuudet? En
Oletko kokeillut toimiiko käyttöliittymä mobiilissa landscape moodissa? Ei koske