Use po files for translation
This commit is contained in:
parent
fda7425f6b
commit
d53f23e830
4 changed files with 69 additions and 1 deletions
28
src/functions/gettext.php
Normal file
28
src/functions/gettext.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gettext.php
|
||||||
|
*
|
||||||
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Gettext\Loader\PoLoader;
|
||||||
|
use Gettext\Generator\MoGenerator;
|
||||||
|
|
||||||
|
function __(string $text)
|
||||||
|
{
|
||||||
|
$userLocale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
$translationFilepath = ROOT . '/translations/' . $userLocale . '.po';
|
||||||
|
|
||||||
|
if (file_exists($translationFilepath)) {
|
||||||
|
$loader = new PoLoader();
|
||||||
|
$translations = $loader->loadFile(ROOT . '/translations/de_DE.po');
|
||||||
|
$translation = $translations->find(null, $text);
|
||||||
|
|
||||||
|
if ($translation) {
|
||||||
|
return $translation->getTranslation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ $page->navigation();
|
||||||
<h1 class="ui header"><?= $page->title ?></h1>
|
<h1 class="ui header"><?= $page->title ?></h1>
|
||||||
|
|
||||||
<div class="ui segment">
|
<div class="ui segment">
|
||||||
<h2 class="ui header">Welcome to wishthis</h2>
|
<h2 class="ui header"><?= __('Welcome to wishthis') ?></h2>
|
||||||
<p>
|
<p>
|
||||||
wishthis is a simple, intuitive and modern wishlist platform to create,
|
wishthis is a simple, intuitive and modern wishlist platform to create,
|
||||||
manage and view your wishes for any kind of occasion.
|
manage and view your wishes for any kind of occasion.
|
||||||
|
|
20
translations/de_DE.po
Normal file
20
translations/de_DE.po
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Jay Trees <github.jay@grandel.anonaddy.me>\n"
|
||||||
|
"POT-Creation-Date: 2022-03-22 08:45+0100\n"
|
||||||
|
"PO-Revision-Date: 2022-03-22 08:48+0100\n"
|
||||||
|
"Last-Translator: Jay Trees <github.jay@grandel.anonaddy.me>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: de_DE\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Generator: Poedit 3.0.1\n"
|
||||||
|
"X-Poedit-Basepath: ../src\n"
|
||||||
|
"X-Poedit-KeywordsList: __\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: pages/home.php:22
|
||||||
|
msgid "Welcome to wishthis"
|
||||||
|
msgstr "Willkommen zu wishthis"
|
20
translations/wishthis.pot
Normal file
20
translations/wishthis.pot
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Jay Trees <github.jay@grandel.anonaddy.me>\n"
|
||||||
|
"POT-Creation-Date: 2022-03-22 08:45+0100\n"
|
||||||
|
"PO-Revision-Date: 2022-03-22 08:45+0100\n"
|
||||||
|
"Last-Translator: Jay Trees <github.jay@grandel.anonaddy.me>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: de_DE\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Generator: Poedit 3.0.1\n"
|
||||||
|
"X-Poedit-Basepath: ../src\n"
|
||||||
|
"X-Poedit-KeywordsList: __\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: pages/home.php:22
|
||||||
|
msgid "Welcome to wishthis"
|
||||||
|
msgstr ""
|
Loading…
Reference in a new issue