translation work 🗣
This commit is contained in:
@@ -143,24 +143,19 @@ function cacheStrings()
|
|||||||
{
|
{
|
||||||
|
|
||||||
// handle core strings and translations
|
// handle core strings and translations
|
||||||
var allLanguages = ["en_us","es_es","de_de"]; // needs to be same as in lang.php
|
var allLanguages = ["en_us", "es_es", "de_de"]; // needs to be same as in lang.php
|
||||||
|
|
||||||
allLanguages.forEach(function (language_code) {
|
allLanguages.forEach(function (language_code) {
|
||||||
|
$.get(`php/templates/language/${language_code}.json`, function (res) {
|
||||||
$.get(`php/templates/language/${language_code}.json`, function(res) {
|
// Iterate over each language
|
||||||
|
Object.entries(res).forEach(([key, value]) => {
|
||||||
Object.entries(res).forEach(([language, translations]) => {
|
// Store translations for each key-value pair
|
||||||
|
setCache(`pia_lang_${key}_${language_code}`, value)
|
||||||
Object.entries(translations).forEach(([key, value]) => {
|
|
||||||
// store as key - value pairs in session
|
|
||||||
setCache(`pia_lang_${key}_${language}`, value)
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
})
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// handle strings and translations from plugins
|
// handle strings and translations from plugins
|
||||||
$.get('api/table_plugins_language_strings.json', function(res) {
|
$.get('api/table_plugins_language_strings.json', function(res) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"de_de": {
|
|
||||||
"API_CUSTOM_SQL_description": "Benutzerdefinierte SQL-Abfrage, welche eine JSON-Datei generiert und diese mit dem <a href=\"/api/table_custom_endpoint.json\" target=\"_blank\">Dateiendpunkt <code>table_custom_endpoint.json</code></a> zur Verf\u00fcgung stellt.",
|
"API_CUSTOM_SQL_description": "Benutzerdefinierte SQL-Abfrage, welche eine JSON-Datei generiert und diese mit dem <a href=\"/api/table_custom_endpoint.json\" target=\"_blank\">Dateiendpunkt <code>table_custom_endpoint.json</code></a> zur Verf\u00fcgung stellt.",
|
||||||
"API_CUSTOM_SQL_name": "Benutzerdefinierte SQL-Abfrage",
|
"API_CUSTOM_SQL_name": "Benutzerdefinierte SQL-Abfrage",
|
||||||
"API_display_name": "API",
|
"API_display_name": "API",
|
||||||
@@ -712,5 +712,5 @@
|
|||||||
"settings_system_label": "",
|
"settings_system_label": "",
|
||||||
"test_event_icon": "fa-vial-circle-check",
|
"test_event_icon": "fa-vial-circle-check",
|
||||||
"test_event_tooltip": "Save your changes at first before you test your settings."
|
"test_event_tooltip": "Save your changes at first before you test your settings."
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"en_us": {
|
|
||||||
"API_CUSTOM_SQL_description": "You can specify a custom SQL query which will generate a JSON file and then expose it via the <a href=\"/api/table_custom_endpoint.json\" target=\"_blank\"><code>table_custom_endpoint.json</code> file endpoint</a>.",
|
"API_CUSTOM_SQL_description": "You can specify a custom SQL query which will generate a JSON file and then expose it via the <a href=\"/api/table_custom_endpoint.json\" target=\"_blank\"><code>table_custom_endpoint.json</code> file endpoint</a>.",
|
||||||
"API_CUSTOM_SQL_name": "Custom endpoint",
|
"API_CUSTOM_SQL_name": "Custom endpoint",
|
||||||
"API_display_name": "API",
|
"API_display_name": "API",
|
||||||
@@ -631,5 +631,5 @@
|
|||||||
"settings_system_label": "System",
|
"settings_system_label": "System",
|
||||||
"test_event_icon": "fa-vial-circle-check",
|
"test_event_icon": "fa-vial-circle-check",
|
||||||
"test_event_tooltip": "Save your changes at first before you test your settings."
|
"test_event_tooltip": "Save your changes at first before you test your settings."
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"es_es": {
|
|
||||||
"API_CUSTOM_SQL_description": "Puede especificar una consulta SQL personalizada que generar\u00e1 un archivo JSON y luego lo expondr\u00e1 a trav\u00e9s del <a href=\"/api/table_custom_endpoint.json\" target=\"_blank\">archivo <code>table_custom_endpoint.json</code ></a>.",
|
"API_CUSTOM_SQL_description": "Puede especificar una consulta SQL personalizada que generar\u00e1 un archivo JSON y luego lo expondr\u00e1 a trav\u00e9s del <a href=\"/api/table_custom_endpoint.json\" target=\"_blank\">archivo <code>table_custom_endpoint.json</code ></a>.",
|
||||||
"API_CUSTOM_SQL_name": "Endpoint personalizado",
|
"API_CUSTOM_SQL_name": "Endpoint personalizado",
|
||||||
"API_display_name": "API",
|
"API_display_name": "API",
|
||||||
@@ -711,5 +711,5 @@
|
|||||||
"settings_system_label": "",
|
"settings_system_label": "",
|
||||||
"test_event_icon": "fa-vial-circle-check",
|
"test_event_icon": "fa-vial-circle-check",
|
||||||
"test_event_tooltip": "Guarda tus cambios antes de probar nuevos ajustes."
|
"test_event_tooltip": "Guarda tus cambios antes de probar nuevos ajustes."
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"fr_fr": {
|
|
||||||
"API_CUSTOM_SQL_description": "",
|
"API_CUSTOM_SQL_description": "",
|
||||||
"API_CUSTOM_SQL_name": "",
|
"API_CUSTOM_SQL_name": "",
|
||||||
"API_display_name": "",
|
"API_display_name": "",
|
||||||
@@ -631,5 +631,5 @@
|
|||||||
"settings_system_label": "",
|
"settings_system_label": "",
|
||||||
"test_event_icon": "",
|
"test_event_icon": "",
|
||||||
"test_event_tooltip": ""
|
"test_event_tooltip": ""
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -31,9 +31,6 @@ function getLanguageDataFromJson()
|
|||||||
{
|
{
|
||||||
global $allLanguages;
|
global $allLanguages;
|
||||||
|
|
||||||
// Default language
|
|
||||||
$defaultLanguage = 'en_us';
|
|
||||||
|
|
||||||
// Array to hold the language data from the JSON files
|
// Array to hold the language data from the JSON files
|
||||||
$languageData = [];
|
$languageData = [];
|
||||||
|
|
||||||
@@ -44,20 +41,18 @@ function getLanguageDataFromJson()
|
|||||||
if (file_exists($jsonFilePath)) {
|
if (file_exists($jsonFilePath)) {
|
||||||
$data = json_decode(file_get_contents($jsonFilePath), true);
|
$data = json_decode(file_get_contents($jsonFilePath), true);
|
||||||
|
|
||||||
// Use the default language if the key is not found
|
// Adjusting for the changed JSON format
|
||||||
$languageData[$language] = $data[$language] ?? $data[$defaultLanguage] ?? [];
|
$languageData[$language] = $data;
|
||||||
} else {
|
} else {
|
||||||
// Handle the case where the JSON file doesn't exist
|
// Handle the case where the JSON file doesn't exist
|
||||||
// For example, you might want to log an error message
|
// For example, you might want to log an error message
|
||||||
echo 'File not found: '.$jsonFilePath;
|
echo 'File not found: ' . $jsonFilePath;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $languageData;
|
return $languageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Merge the JSON data with the SQL data, giving priority to SQL data for overlapping keys
|
// Merge the JSON data with the SQL data, giving priority to SQL data for overlapping keys
|
||||||
function mergeLanguageData($jsonLanguageData, $sqlLanguageData)
|
function mergeLanguageData($jsonLanguageData, $sqlLanguageData)
|
||||||
{
|
{
|
||||||
@@ -76,30 +71,31 @@ function mergeLanguageData($jsonLanguageData, $sqlLanguageData)
|
|||||||
|
|
||||||
function lang($key)
|
function lang($key)
|
||||||
{
|
{
|
||||||
global $pia_lang_selected, $lang, $defaultLang, $strings, $db;
|
global $pia_lang_selected, $strings;
|
||||||
// Get the data from JSON files
|
|
||||||
$languageData = getLanguageDataFromJson();
|
|
||||||
|
|
||||||
// Get the data from SQL query
|
// Get the data from JSON files
|
||||||
$sqlLanguageData = $strings;
|
$languageData = getLanguageDataFromJson();
|
||||||
|
|
||||||
// Merge JSON data with SQL data
|
// Get the data from SQL query
|
||||||
$mergedLanguageData = mergeLanguageData($languageData, $sqlLanguageData);
|
$sqlLanguageData = $strings;
|
||||||
|
|
||||||
// Check if the key exists in the selected language
|
// Merge JSON data with SQL data
|
||||||
if (isset($mergedLanguageData[$pia_lang_selected][$key]) and $mergedLanguageData[$pia_lang_selected][$key] != '') {
|
$mergedLanguageData = mergeLanguageData($languageData, $sqlLanguageData);
|
||||||
$result = $mergedLanguageData[$pia_lang_selected][$key];
|
|
||||||
} else {
|
// Check if the key exists in the selected language
|
||||||
// If key not found in selected language, use "en_us" as fallback
|
if (isset($mergedLanguageData[$pia_lang_selected][$key]) && $mergedLanguageData[$pia_lang_selected][$key] != '') {
|
||||||
if (isset($mergedLanguageData['en_us'][$key])) {
|
$result = $mergedLanguageData[$pia_lang_selected][$key];
|
||||||
$result = $mergedLanguageData['en_us'][$key];
|
|
||||||
} else {
|
} else {
|
||||||
// If key not found in "en_us" either, use a default string
|
// If key not found in selected language, use "en_us" as fallback
|
||||||
$result = "String Not found for key " . $key;
|
if (isset($mergedLanguageData['en_us'][$key])) {
|
||||||
|
$result = $mergedLanguageData['en_us'][$key];
|
||||||
|
} else {
|
||||||
|
// If key not found in "en_us" either, use a default string
|
||||||
|
$result = "String Not found for key " . $key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"nb_no": {
|
|
||||||
"API_CUSTOM_SQL_description": "",
|
"API_CUSTOM_SQL_description": "",
|
||||||
"API_CUSTOM_SQL_name": "",
|
"API_CUSTOM_SQL_name": "",
|
||||||
"API_display_name": "",
|
"API_display_name": "",
|
||||||
@@ -631,5 +631,5 @@
|
|||||||
"settings_system_label": "",
|
"settings_system_label": "",
|
||||||
"test_event_icon": "",
|
"test_event_icon": "",
|
||||||
"test_event_tooltip": ""
|
"test_event_tooltip": ""
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user