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

Initial version of localization #12

Merged
merged 11 commits into from
May 23, 2024
Merged

Initial version of localization #12

merged 11 commits into from
May 23, 2024

Conversation

SalamaGofore
Copy link
Contributor

@SalamaGofore SalamaGofore commented May 16, 2024

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

@SalamaGofore SalamaGofore force-pushed the OK-495-lokalisointi branch 2 times, most recently from c4f53ef to 241820a Compare May 16, 2024 06:40
@SalamaGofore SalamaGofore force-pushed the OK-495-lokalisointi branch from 0b9c2bf to 7d46879 Compare May 17, 2024 13:14
@SalamaGofore SalamaGofore marked this pull request as ready for review May 21, 2024 09:16

Aja yksikkötestit komennolla:

`npm test`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`npm test`
`npm run test`

Copy link
Contributor Author

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

Copy link
Contributor

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`
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Comment on lines 1 to 59
{
"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"
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

@SalamaGofore SalamaGofore May 23, 2024

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 }) {
Copy link
Contributor

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,
Copy link
Contributor

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";

Suggested change
t: (s: string) => string,
t: TFunction,

Comment on lines 4 to 22
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';
};
Copy link
Contributor

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)
Copy link
Contributor

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

}

function getTranslationsFromFile(lng: string) {
console.log('getTranslationsFromFile ' + lng);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log('getTranslationsFromFile ' + lng);

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const lng = searchParams.get('lng') || 'fi';
if (!isProd && isDev && isLocalhost) {
Copy link
Contributor

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.

Suggested change
if (!isProd && isDev && isLocalhost) {
if (isDev && isLocalhost) {

@SalamaGofore SalamaGofore force-pushed the OK-495-lokalisointi branch from 337c3b7 to f76b854 Compare May 23, 2024 10:27
@SalamaGofore SalamaGofore merged commit 27a82ce into main May 23, 2024
8 checks passed
@SalamaGofore SalamaGofore deleted the OK-495-lokalisointi branch May 23, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants