diff --git a/.gpt-po/dictionary.json b/.gpt-po/dictionary.json
new file mode 100644
index 0000000..492fbb7
--- /dev/null
+++ b/.gpt-po/dictionary.json
@@ -0,0 +1,4 @@
+{
+ "Speculoos World" : "a virtual world grid name",
+ "helper" : "a web application complementing OpenSimulator features, must be treated as a software application, not a human assistant."
+}
diff --git a/.gpt-po/systemprompt.txt b/.gpt-po/systemprompt.txt
new file mode 100644
index 0000000..9b0e7ed
--- /dev/null
+++ b/.gpt-po/systemprompt.txt
@@ -0,0 +1 @@
+You are an awesome translator! Please translate the following text in a casual and approachable style, suitable for a friendly WordPress plugin interface. Avoid overly formal language and aim for a more relaxed and user-friendly tone, and sounding like a machine translation. All inputs are phrases to translate. "Yes" or "No" are not remarks to you, they are the actual strings to translate. Original language is English, the response should never be in English but in the target language. Remember to always translate the text, never interpret it, and never explain it. The project is a PHP library for use in OpenSimulator virtual world environment.
diff --git a/guide.php b/guide.php
index c528764..8e2fe50 100644
--- a/guide.php
+++ b/guide.php
@@ -26,7 +26,7 @@ class OpenSim_Guide {
private $source;
public function __construct() {
- error_log( 'language ' . getPreferredLanguage() );
+ set_helpers_locale();
$this->url_base = $this->getFullURL();
@@ -85,7 +85,7 @@ class OpenSim_Guide {
$lines = explode( "\n", $fileContent );
- $categoryTitle = 'Destinations list';
+ $categoryTitle = _('Destinations Guide');
foreach ( $lines as $line ) {
// Exclude lines starting with "#" or "//" or containing no actual characters
if ( substr( trim( $line ), 0, 1 ) === '#' || substr( trim( $line ), 0, 2 ) === '//' || ! trim( $line ) ) {
@@ -125,8 +125,8 @@ class OpenSim_Guide {
public function categories_list() {
$content = '
'
. '';
foreach ( $this->destinations as $categoryTitle => $destinations ) {
@@ -135,7 +135,8 @@ class OpenSim_Guide {
. '
'
. '
 . ')
'
. '
' . $categoryTitle . '
'
- . '
' . count( $destinations ) . ' destinations
'
+ # Translators: %s will be replaced with the number of destinations
+ . '
' . sprintf( _('%s destinations'), count( $destinations ) ) . '
'
. '
'
. '';
}
@@ -148,9 +149,9 @@ class OpenSim_Guide {
// Build header
$content = '';
// Build list
@@ -164,11 +165,11 @@ class OpenSim_Guide {
. '
' . $destination['name'] . '
'
. '
';
if ( $people > 0 ) {
- $content .= ' ' . $this->place_people() . ' people ';
+ $content .= ' ' . sprintf( _('%s people'), $this->place_people() ) . ' ';
}
if ( $traffic > 0 ) {
- $content .= ' Traffic: ' . $this->place_traffic() . ' ';
- }
+ $content .= ' ' . sprintf( _('traffic %s'), $this->place_traffic() ) . ' ';
+ }
$content .= '
';
}
$content .= '';
@@ -178,7 +179,7 @@ class OpenSim_Guide {
private function no_result() {
echo '';
- echo 'The realm of destinations you seek has eluded our grasp, spirited away by elusive knomes. Rally the grid managers, let them venture forth to curate a grand tapestry of remarkable places for your exploration!';
+ echo _('The realm of destinations you seek has eluded our grasp, spirited away by elusive knomes. Rally the grid managers, let them venture forth to curate a grand tapestry of remarkable places for your exploration!');
echo '
';
echo $this->getFullURL() . "?source=$this->source";
}
diff --git a/includes/functions.php b/includes/functions.php
index 1743087..326e08b 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -410,6 +410,48 @@ if ( ! function_exists( 'osdebug' ) ) {
}
}
+function set_helpers_locale( $locale = null, $domain = 'messages' ) {
+ mb_internal_encoding('UTF-8');
+ $encoding = mb_internal_encoding();
+
+ if (isset($_GET["l"])) $locale = $_GET["l"];
+ $languages = array_filter(array_merge( array($locale), explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) ));
+
+ // $results = putenv("LC_ALL=$locale");
+ // if (!$results) {
+ // exit ('putenv failed');
+ // }
+
+ // $currentLocale = setlocale(LC_ALL, 0);
+ $user_locales = array_unique(array( $locale, $locale . ".$encoding", $locale . '.UTF-8', $locale . '.utf8', $locale, 0 ));
+
+ $user_locales = array_map(function ($code) {
+ return preg_replace(
+ array('/;.*/', '/-/' ),
+ array ('', '_'),
+ $code
+ );
+ }, $languages);
+
+ // Generate variants with different encodings appended
+ $variants = array();
+ foreach ($user_locales as $lang) {
+ $variants[] = $lang;
+ $variants[] = "$lang.$encoding";
+ // $variants[] = "$lang.UTF-8";
+ }
+
+ $variants = array_unique($variants);
+ if ( ! setlocale(LC_ALL, $variants ) ) {
+ error_log ("setlocale() failed: none of '" . join(', ', $variants) . "' does exist in this environment or setlocale() is not available on this platform");
+ setlocale(LC_ALL, 0 );
+ return 0;
+ }
+
+ bindtextdomain($domain, "./locales");
+ textdomain($domain);
+}
+
define( 'NULL_KEY', '00000000-0000-0000-0000-000000000000' );
define( 'TPLINK_LOCAL', 1 ); // seconlife://Region/x/y/z
define( 'TPLINK_HG', 2 ); // seconlife://yourgrid.org:8002 Region/x/y/z
@@ -421,6 +463,7 @@ define( 'TPLINK_MAP', 64 ); // secondlife:///app/map/yourgrid.org:8002:Region/x/
define( 'TPLINK', pow( 2, 8 ) - 1 ); // all formats
define( 'TPLINK_DEFAULT', TPLINK_HOP ); // default
+define( 'HELPERS_LOCALE_DIR', dirname( __DIR__ ) . '/languages' );
/**
* OpenSim source to help further attempts to allow Hypergrid search results.
diff --git a/locales/cy_GB/LC_MESSAGES/messages.mo b/locales/cy_GB/LC_MESSAGES/messages.mo
new file mode 100644
index 0000000..ecca178
Binary files /dev/null and b/locales/cy_GB/LC_MESSAGES/messages.mo differ
diff --git a/locales/cy_GB/LC_MESSAGES/messages.po b/locales/cy_GB/LC_MESSAGES/messages.po
new file mode 100644
index 0000000..fcb285b
--- /dev/null
+++ b/locales/cy_GB/LC_MESSAGES/messages.po
@@ -0,0 +1,52 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: \n"
+"Last-Translator: gpt-po v1.0.7\n"
+"Language-Team: \n"
+"Language: cy_GB\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 3.0.1\n"
+
+#: guide.php:88 guide.php:128
+msgid "Destinations Guide"
+msgstr "Canllaw Cyrchfannau"
+
+#: guide.php:129 guide.php:154
+msgid "This is a work in progress, please be indulgent."
+msgstr "Gwaith ar y gweill yw hwn, cewch fod yn amyneddgar."
+
+#: guide.php:139
+#, php-format
+msgid "%s destinations"
+msgstr "%s cyfeiriadau"
+
+#: guide.php:152
+msgid "Back to categories"
+msgstr "Yn ôl i gategorïau"
+
+#: guide.php:168
+#, php-format
+msgid "%s people"
+msgstr "%s pobl"
+
+#: guide.php:170
+#, php-format
+msgid "traffic %s"
+msgstr "llywio %s"
+
+#: guide.php:182
+msgid ""
+"The realm of destinations you seek has eluded our grasp, spirited away by elusive knomes. Rally the grid managers, let "
+"them venture forth to curate a grand tapestry of remarkable places for your exploration!"
+msgstr ""
+"I ddiffodd ein gafael ar y ddaear o gyrchfeydd a hoffech, clywir hwynt yn taro drwy 'nawdd y tylwyth teg. Ysgogi'r "
+"rheolwyr grid, gadewch iddynt anterth i guradu tapistry mawr o leoliadau rhyfeddol ar gyfer eich archwilio!"
diff --git a/locales/de_DE/LC_MESSAGES/messages.mo b/locales/de_DE/LC_MESSAGES/messages.mo
new file mode 100644
index 0000000..08c0ec1
Binary files /dev/null and b/locales/de_DE/LC_MESSAGES/messages.mo differ
diff --git a/locales/de_DE/LC_MESSAGES/messages.po b/locales/de_DE/LC_MESSAGES/messages.po
new file mode 100644
index 0000000..c818c06
--- /dev/null
+++ b/locales/de_DE/LC_MESSAGES/messages.po
@@ -0,0 +1,52 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: \n"
+"Last-Translator: gpt-po v1.0.7\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"
+"X-Generator: Poedit 3.0.1\n"
+
+#: guide.php:88 guide.php:128
+msgid "Destinations Guide"
+msgstr "Reiseführer für Ziele"
+
+#: guide.php:129 guide.php:153
+msgid "This is a work in progress, please be indulgent."
+msgstr "Dies ist eine Arbeit in Bearbeitung, bitte seien Sie nachsichtig."
+
+#: guide.php:138
+#, php-format
+msgid "%s destinations"
+msgstr "%s Ziele"
+
+#: guide.php:151
+msgid "Back to categories"
+msgstr "Zurück zu den Kategorien"
+
+#: guide.php:167
+#, php-format
+msgid "%s people"
+msgstr "%s Personen"
+
+#: guide.php:170
+#, php-format
+msgid "traffic %s"
+msgstr "Verkehr %s"
+
+#: guide.php:181
+msgid ""
+"The realm of destinations you seek has eluded our grasp, spirited away by elusive knomes. Rally the grid managers, let "
+"them venture forth to curate a grand tapestry of remarkable places for your exploration!"
+msgstr ""
+"Die Welt der Ziele, die du suchst, ist uns entwischt, von flüchtigen Gnomen fortgetragen. Rufe die Grid-Manager "
+"zusammen, lass sie sich aufmachen, um eine großartige Vielfalt bemerkenswerter Orte für deine Erkundung zu kuratieren!"
diff --git a/locales/fr_FR/LC_MESSAGES/messages.mo b/locales/fr_FR/LC_MESSAGES/messages.mo
new file mode 100644
index 0000000..2daf4ee
Binary files /dev/null and b/locales/fr_FR/LC_MESSAGES/messages.mo differ
diff --git a/locales/fr_FR/LC_MESSAGES/messages.po b/locales/fr_FR/LC_MESSAGES/messages.po
new file mode 100644
index 0000000..f89b22c
--- /dev/null
+++ b/locales/fr_FR/LC_MESSAGES/messages.po
@@ -0,0 +1,52 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: \n"
+"Last-Translator: gpt-po v1.0.7\n"
+"Language-Team: \n"
+"Language: fr_FR\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 3.0.1\n"
+
+#: guide.php:88 guide.php:128
+msgid "Destinations Guide"
+msgstr "Guide des destinations"
+
+#: guide.php:129 guide.php:153 locale.php:71
+msgid "This is a work in progress, please be indulgent."
+msgstr "Ceci est un travail en cours, veuillez faire preuve d'indulgence."
+
+#: guide.php:138
+#, php-format
+msgid "%s destinations"
+msgstr "%s destinations"
+
+#: guide.php:151 locale.php:73
+msgid "Back to categories"
+msgstr "Retour aux catégories"
+
+#: guide.php:167
+#, php-format
+msgid "%s people"
+msgstr "%s personnes"
+
+#: guide.php:170
+#, php-format
+msgid "traffic %s"
+msgstr "trafic %s"
+
+#: guide.php:181
+msgid ""
+"The realm of destinations you seek has eluded our grasp, spirited away by elusive knomes. Rally the grid managers, let "
+"them venture forth to curate a grand tapestry of remarkable places for your exploration!"
+msgstr ""
+"Le royaume des destinations que vous recherchez nous échappe, emporté par des lutins insaisissables. Rassemblez les "
+"gestionnaires de la grille, laissez-les s'aventurer pour créer une grande fresque de lieux remarquables à explorer !"
diff --git a/locales/it_IT/LC_MESSAGES/messages.mo b/locales/it_IT/LC_MESSAGES/messages.mo
new file mode 100644
index 0000000..09ddf40
Binary files /dev/null and b/locales/it_IT/LC_MESSAGES/messages.mo differ
diff --git a/locales/it_IT/LC_MESSAGES/messages.po b/locales/it_IT/LC_MESSAGES/messages.po
new file mode 100644
index 0000000..99185bf
--- /dev/null
+++ b/locales/it_IT/LC_MESSAGES/messages.po
@@ -0,0 +1,52 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: \n"
+"Last-Translator: gpt-po v1.0.7\n"
+"Language-Team: \n"
+"Language: it_IT\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 3.0.1\n"
+
+#: guide.php:88 guide.php:128
+msgid "Destinations Guide"
+msgstr "Guida delle destinazioni"
+
+#: guide.php:129 guide.php:153
+msgid "This is a work in progress, please be indulgent."
+msgstr "Questo è un lavoro in corso, per favore sii indulgente."
+
+#: guide.php:138
+#, php-format
+msgid "%s destinations"
+msgstr "%s destinazioni"
+
+#: guide.php:151
+msgid "Back to categories"
+msgstr "Torna alle categorie"
+
+#: guide.php:167
+#, php-format
+msgid "%s people"
+msgstr "%s persone"
+
+#: guide.php:170
+#, php-format
+msgid "traffic %s"
+msgstr "traffico %s"
+
+#: guide.php:182
+msgid ""
+"The realm of destinations you seek has eluded our grasp, spirited away by elusive knomes. Rally the grid managers, let "
+"them venture forth to curate a grand tapestry of remarkable places for your exploration!"
+msgstr ""
+"Il regno delle destinazioni che cerchi ci sfugge, portato via da gnomi sfuggenti. Raduna i gestori della griglia, "
+"lasciali avventurarsi per creare un magnifico mosaico di luoghi straordinari da esplorare!"
diff --git a/locales/messages.pot b/locales/messages.pot
new file mode 100644
index 0000000..168c169
--- /dev/null
+++ b/locales/messages.pot
@@ -0,0 +1,52 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2023-08-02 19:44-0400\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: guide.php:88 guide.php:128
+msgid "Destinations Guide"
+msgstr ""
+
+#: guide.php:129 guide.php:154
+msgid "This is a work in progress, please be indulgent."
+msgstr ""
+
+#: guide.php:139
+#, php-format
+msgid "%s destinations"
+msgstr ""
+
+#: guide.php:152
+msgid "Back to categories"
+msgstr ""
+
+#: guide.php:168
+#, php-format
+msgid "%s people"
+msgstr ""
+
+#: guide.php:171
+#, php-format
+msgid "traffic %s"
+msgstr ""
+
+#: guide.php:182
+msgid ""
+"The realm of destinations you seek has eluded our grasp, spirited away by "
+"elusive knomes. Rally the grid managers, let them venture forth to curate a "
+"grand tapestry of remarkable places for your exploration!"
+msgstr ""
diff --git a/locales/pt_BR/LC_MESSAGES/messages.mo b/locales/pt_BR/LC_MESSAGES/messages.mo
new file mode 100644
index 0000000..b559064
Binary files /dev/null and b/locales/pt_BR/LC_MESSAGES/messages.mo differ
diff --git a/locales/pt_BR/LC_MESSAGES/messages.po b/locales/pt_BR/LC_MESSAGES/messages.po
new file mode 100644
index 0000000..1632fd2
--- /dev/null
+++ b/locales/pt_BR/LC_MESSAGES/messages.po
@@ -0,0 +1,52 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: \n"
+"Last-Translator: gpt-po v1.0.7\n"
+"Language-Team: \n"
+"Language: pt_BR\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 3.0.1\n"
+
+#: guide.php:88 guide.php:128
+msgid "Destinations Guide"
+msgstr "Guia de Destinos"
+
+#: guide.php:129 guide.php:153
+msgid "This is a work in progress, please be indulgent."
+msgstr "Este é um trabalho em andamento, por favor, seja indulgente."
+
+#: guide.php:138
+#, php-format
+msgid "%s destinations"
+msgstr "%s destinos"
+
+#: guide.php:151
+msgid "Back to categories"
+msgstr "Voltar para categorias"
+
+#: guide.php:167
+#, php-format
+msgid "%s people"
+msgstr "%s pessoas"
+
+#: guide.php:170
+#, php-format
+msgid "traffic %s"
+msgstr "tráfego %s"
+
+#: guide.php:182
+msgid ""
+"The realm of destinations you seek has eluded our grasp, spirited away by elusive knomes. Rally the grid managers, let "
+"them venture forth to curate a grand tapestry of remarkable places for your exploration!"
+msgstr ""
+"O reino de destinos que você procura escapou de nosso alcance, levado embora por gnomos elusivos. Reúna os gerentes da "
+"grid, deixe-os se aventurar para criar uma grande tapeçaria de lugares notáveis para sua exploração!"
diff --git a/locales/update_translations.sh b/locales/update_translations.sh
new file mode 100755
index 0000000..b2f01df
--- /dev/null
+++ b/locales/update_translations.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+find * -iname "*.php" | egrep -v -e vendor -e node_modules | xargs -d"\n" xgettext --from-code=UTF-8 -o locales/messages.pot
+
+pot=locales/messages.pot
+
+for lang in fr_FR de_DE cy_GB it_IT pt_BR
+do
+ file="locales/$lang/LC_MESSAGES/messages.po"
+
+ mkdir -p "$(dirname "$file")" && touch $file \
+ && gpt-po sync --po "$file" --pot "$pot" \
+ && gpt-po translate --po "$file" -l $lang \
+ && poedit "$file"
+
+done