Skip to content

Commit

Permalink
Arreglada seleccion del idioma por default: no permitir es-419, es-PE…
Browse files Browse the repository at this point in the history
…, etc
  • Loading branch information
jacargentina committed Apr 8, 2024
1 parent 0f5dda6 commit ad014ce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/web/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function App() {
navigate('/list');
}
} else {
console.log('no locale yet. POST /lang/' + navigator.language);
fetcher.submit(null, {
action: '/lang/' + navigator.language,
method: 'post',
Expand Down
23 changes: 22 additions & 1 deletion packages/web/app/routes/lang.$locale.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { getLocalesForPicker } from '@iresucito/core';
import { ActionFunction } from '@remix-run/node';
import { json } from '@vercel/remix';
import { commitSession, getSession } from '~/session.server';

export let action: ActionFunction = async ({ request, params }) => {
const { locale } = params;
const session = await getSession(request.headers.get('Cookie'));
session.set('locale', locale);

const availableLocales = getLocalesForPicker();
// Buscar coincidencia completa (es-419, es-PE)
var search = availableLocales.find((v) => v.value == locale);
console.log(`lang ${locale} valid?: ${search != undefined ? 'YES' : 'NO'}`);
if (search == undefined && locale?.split('-').length == 2) {
// Ej "es-419", buscar "es"
search = availableLocales.find((v) => v.value == locale?.split('-')[0]);
console.log(
`lang ${locale?.split('-')[0]} ?: ${search != undefined ? 'YES' : 'NO'}`
);
}

if (!search) {
search = availableLocales[0];
console.log(`lang set to first available: ${search.value}`);
}

session.set('locale', search.value);
console.log('lang set', search.value);

return json(
{ newLocale: locale },
{
Expand Down

0 comments on commit ad014ce

Please sign in to comment.