Localization changes

This commit is contained in:
Dendy 2023-01-10 15:54:42 +01:00
parent f9d3370574
commit 599da85947
5 changed files with 162 additions and 42 deletions

View File

@ -17,10 +17,50 @@ contact = "Contacte"
programming = "Programació" programming = "Programació"
git = "Perfil git" git = "Perfil git"
keys = "Claus"
# main page # main page
welcome = "Text per ocupar el espai" welcomeHeader = "Yepa!"
welcome = "
<p>Hola i benvingudi a la meua pàgina</p>
<p>
Ací allotje les coses que fet així com
les que estic fent actualment, opinions
candents, coses que crec que mereixen ser
compartides i coses que me representen com
persona.
</p>
<p>
Si vols saber més de mí pots vore-ho
ací o pots contactar-me.
</p>
<p>
Espere que trobes coses que siguen del teu interés.
</p>
"
projectsHeader = "Projects"
projects = "
<h3>fai.st</h3>
<p>
Allotje i administre una sèrie de serveis de programari
lliure (un servidor fediversal, una instancia de Gitea, servei
VPN...) amb el nomb de <b>fai.st</b> amb uns amics.
</p>
<h3>USG</h3>
<p>
Clon competitiu del Tetris que busca ser correcte. Realitzat en
el llenguatge zig y amb la llibreria de SDL i renderització OpenGL.
Majoritariament fet el propòsit de aprendre.
</p>
<h3>keno</h3>
<p>
Client i biblioteca per a consumir la API de Mastodon gastant GTK i C.
Actualmen no està en desevolupament actiu.
</p>
"
# footer # footer
copyright = "Aquesta pàgina està baix la llicència GPLv3 i el seu codi font estarà diponible prompte™. Els recursos utilitzats en aquesta pàgina estan baix CC-SA si no se especifica lo contrari." copyright = "Aquesta pàgina està baix la llicència GPLv3 i el seu codi font estarà diponible prompte™. Els recursos utilitzats en aquesta pàgina estan baix CC-BY-NC-SA si no se especifica lo contrari."

View File

@ -16,10 +16,49 @@ contact = "Contact"
programming = "Programming" programming = "Programming"
git = "Git profile" git = "Git profile"
keys = "Keys"
# main page # main page
welcome = "Text to occupy space" welcomeHeader = "Hi"
welcome = "
<p>Hello and welcome to my place!</p>
<p>
Here I'm hosting the things I've done,
thing's im currently doing, my hot takes
and things that I think are worth sharing
and represent who I am as a being
</p>
<p>
If you want to know more about me you
can see it here or contact me.
</p>
<p>
Hope you find something that interests you.
</p>
"
projectsHeader = "Projects"
projects = "
<h3>fai.st</h3>
<p>
I host and manage a number of free software services
(a fediverse server, Gitea instance, VPN...)
under the name <b>fai.st</b> alongside some friends.
</p>
<h3>USG</h3>
<p>
Proper competitive tetris clone made in ziglang and SDL2,
with OpenGL rendering. Mostly made for learning purposes.
</p>
<h3>keno</h3>
<p>
Mastodon-API client and library using C and GTK. Not under
active development anymore.
</p>
"
# footer # footer
copyright = "This website is under the GPLv3 license and its source code will be avalible soon™. The resources used on this website are under CC-SA unless stated otherwise." copyright = "This website is under the GPLv3 license and its source code will be avalible soon™. The resources used on this website are under CC-BY-NC-SA unless stated otherwise."

View File

@ -17,10 +17,49 @@ contact = "Contacto"
programming = "Programación" programming = "Programación"
git = "Perfil git" git = "Perfil git"
keys = "Claves"
# main page # main page
welcome = "Texto para ocupar espacio" welcomeHeader = "¡Buenas!"
welcome = "
<p>Hola y bienvenide a mi página</p>
<p>
Aquí alojo las cosas que hecho así como
las que estoy actualmente haciendo, opiniones
candentes, cosas que creo que vale la pena
compartir y cosas que me representan como persona.
</p>
<p>
Si quieres saber más sobre mí lo puedes ver
aquí o puedes contactarme.
</p>
<p>
Espero que encuentres cosas que te sean de interés.
</p>
"
projectsHeader = "Projects"
projects = "
<h3>fai.st</h3>
<p>
Alojo y administro una serie de servicios sofware libre
(un servidor fediversal, una instancia de Gitea, servicio VPN...)
bajo el nombre <b>fai.st</b> con unos amigos.
</p>
<h3>USG</h3>
<p>
Clon competitivo del Tetris de implementación correcta realizado
en ziglang y SDL2, con renderización mediante OpenGL. Mayoritariamente
hecho con el propósito de aprender.
</p>
<h3>keno</h3>
<p>
Cliente y biblioteca para consumir la API de Mastodon usando GTK y C.
Actualmente no está en desarrollo activo.
</p>
"
# footer # footer
copyright = "Esta página está bajo la licencia GPLv3 y su código fuente estará diponible pronto™. Los recursos usados en esta página están bajo CC-SA a no ser que se diga lo contrario." copyright = "Esta página está bajo la licencia GPLv3 y su código fuente estará diponible pronto™. Los recursos usados en esta página están bajo CC-BY-NC-SA a no ser que se diga lo contrario."

View File

@ -22,4 +22,4 @@ keys = "Kweys"
welcome = "Tewxt to occupy spwace >:3c" welcome = "Tewxt to occupy spwace >:3c"
# footer # footer
copyright = "Twis website is unwer the GPLv3 wicense and its sowwse code avawwable soon™. De wesources used on this webwsite are under CC-SA unwess stated oderwise. UwU" copyright = "Twis website is unwer the GPLv3 wicense and its sowwse code avawwable soon™. De wesources used on this webwsite are under CC-BY-NC-SA unwess stated oderwise. UwU"

View File

@ -1,7 +1,7 @@
<?php <?php
///////////////////////////////////////////////// /////////////////////////////////////////////////
// Avaliable variables after importing this file // Avaliable variables after importing this file
///////////////////////////////////////////////// /////////////////////////////////////////////////
// The actual language being used // The actual language being used
@ -9,7 +9,9 @@ $lang = null;
// Avaliable detected languages // Avaliable detected languages
$langs = []; $langs = [];
// Function that gets the strings // Function that gets the strings
$trans = function(){ return 'N/A'; }; $trans = function () {
return 'N/A';
};
/* I use functions to create scopes. Anything below /* I use functions to create scopes. Anything below
* shouldn't be accesible from outside * shouldn't be accesible from outside
@ -17,83 +19,83 @@ $trans = function(){ return 'N/A'; };
/* -------------------------------------------------*/ /* -------------------------------------------------*/
$__langfunc = function() use (&$lang, &$langs, &$trans){ $__langfunc = function () use (&$lang, &$langs, &$trans) {
/////////////// ///////////////
/// Get basedir /// Get basedir
/////////////// ///////////////
// DOCUMENT_ROOT makes sure we always get the right folder // DOCUMENT_ROOT makes sure we always get the right folder
$basedir = sprintf('%s/lang', $_SERVER['DOCUMENT_ROOT']); $basedir = sprintf('%s/lang', $_SERVER['DOCUMENT_ROOT']);
/////////////////////////////////////// ///////////////////////////////////////
/// Get the languages we have avaliable /// Get the languages we have avaliable
/////////////////////////////////////// ///////////////////////////////////////
// To get the langs we scan the folder with the ini files // To get the langs we scan the folder with the ini files
$langs = scandir($basedir); $langs = scandir($basedir);
// Filter for those that have to letters and end in ".ini" // Filter for those that have two letters and end in ".ini"
$langs = array_filter($langs, fn($x) => preg_match('/.*\.ini/', $x) === 1); $langs = array_filter($langs, fn ($x) => preg_match('/.*\.ini/', $x) === 1);
// And we remove the ".ini" part // And we remove the ".ini" part
$langs = array_map(fn($x) => substr($x, 0, 2), $langs); $langs = array_map(fn ($x) => substr($x, 0, 2), $langs);
//////////////////////////////////// ////////////////////////////////////
/// Get the optimal language to use /// Get the optimal language to use
//////////////////////////////////// ////////////////////////////////////
/* Try to get the language from browser-sent headers. The /* Try to get the language from browser-sent headers. The
* format for the header is like this: "en_US,es;q=0.5,ar;q=0.1". * format for the header is like this: "en_US,es;q=0.5,ar;q=0.1".
* q=N represents the weight of preference, no q means q=1.0. * q=N represents the weight of preference, no q means q=1.0.
*/ */
{ if ($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? false) {
// Divide language string per language // Divide language string per language
$http_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); $http_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
// Sanitize lang string and cast weight // Sanitize lang string and cast weight
$http_langs = array_map(function($x){ $http_langs = array_map(function ($x) {
$x = explode(';',$x); $x = explode(';', $x);
$x[0] = strtolower(substr($x[0], 0, 2)); $x[0] = strtolower(substr($x[0], 0, 2));
$x[1] = (float)(explode('=',$x[1]??'q=1.0')[1]??1.0); $x[1] = (float)(explode('=', $x[1] ?? 'q=1.0')[1] ?? 1.0);
return $x; return $x;
}, $http_langs); }, $http_langs);
// Sort by weight // Sort by weight
usort($http_langs, function($a, $b){ usort($http_langs, function ($a, $b) {
if($a[1] === $b[1]) return 0; if ($a[1] === $b[1]) return 0;
return ($a[1] > $b[1]) ? -1 : 1; return ($a[1] > $b[1]) ? -1 : 1;
}); });
// Create new neat array like this: ['en', 'es', 'ar'] // Create new neat array like this: ['en', 'es', 'ar']
$user_langs = []; $user_langs = [];
array_walk($http_langs, function($arr) use (&$user_langs){ array_walk($http_langs, function ($arr) use (&$user_langs) {
if(!in_array($arr[0], $user_langs)) $user_langs[] = $arr[0]; if (!in_array($arr[0], $user_langs)) $user_langs[] = $arr[0];
}); });
// Assign the first match // Assign the first match
foreach($user_langs as $ilang){ foreach ($user_langs as $ilang) {
if(in_array($ilang, $langs)) { if (in_array($ilang, $langs)) {
$lang = $ilang; $lang = $ilang;
break; break;
} }
} }
} }
// Manully selected lang > HTTP lang > fallback lang // Manully selected lang > HTTP lang > fallback lang
$lang = ($_GET['lang']??null) ?: $lang ?: 'en'; $lang = ($_GET['lang'] ?? null) ?: $lang ?: 'en';
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
/// Get file and build function to get the strings /// Get file and build function to get the strings
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
$text = parse_ini_file("$basedir/$lang.ini", true); $text = parse_ini_file("$basedir/$lang.ini", true);
$trans = function (string $index) use ($text): string{ $trans = function (string $index) use ($text): string {
return htmlspecialchars($text[$index]??"N/A", ENT_QUOTES); // return htmlspecialchars($text[$index] ?? 'N/A', ENT_QUOTES);
return $text[$index] ?? 'N/A';
}; };
}; };