Skip to content

Commit

Permalink
Language API and strings fixes
Browse files Browse the repository at this point in the history
- Reverts Array-style message format
- Updates to language strings file headers

This partially redoes grangeway's recent modifications to these files,
except that the translated files have not been changed as this should be
done automatically with translatewiki updates.
  • Loading branch information
dregad committed Oct 12, 2013
2 parents faaa92b + 4c25e01 commit 8863144
Show file tree
Hide file tree
Showing 141 changed files with 3,403 additions and 2,299 deletions.
6 changes: 5 additions & 1 deletion admin/test_langs.php
Expand Up @@ -118,7 +118,11 @@ function checklangdir( $p_path, $p_lang_files = null ) {
}
// Skipping english language, readme and hidden files
foreach( $t_lang_files as $key => $t_lang ) {
if( $t_lang[0] == '.' || $t_lang == 'langreadme.txt' || $t_lang == STRINGS_ENGLISH ) {
if( $t_lang[0] == '.'
|| $t_lang == 'langreadme.txt'
|| $t_lang == 'README'
|| $t_lang == STRINGS_ENGLISH
) {
unset( $t_lang_files[$key] );
}
}
Expand Down
106 changes: 30 additions & 76 deletions core/lang_api.php
Expand Up @@ -66,8 +66,6 @@ function lang_load( $p_lang, $p_dir = null ) {
return;
}

// Step 1 - Load Requested Language file
// @@ and if file doesn't exist???
if( $p_dir === null ) {
include_once( config_get( 'language_path' ) . 'strings_' . $p_lang . '.txt' );
} else {
Expand All @@ -76,68 +74,31 @@ function lang_load( $p_lang, $p_dir = null ) {
}
}

// Step 2 - Allow overriding strings declared in the language file.
// custom_strings_inc.php can use $g_active_language
// 2 formats:
// $s_* - old format
// $s_custom_strings array - new format
// NOTE: it's not expected that you'd mix/merge old/new formats within this file.
$t_custom_strings = config_get( 'custom_strings_file' ) ;
# Allow overriding strings declared in the language file.
# custom_strings_inc.php can use $g_active_language
$t_custom_strings = config_get( 'absolute_path' ) . 'custom_strings_inc.php';
if( file_exists( $t_custom_strings ) ) {
# this may be loaded multiple times, once per language
require( $t_custom_strings );
}

// Step 3 - New Language file format
// Language file consists of an array
if( isset( $s_messages ) ) {
// lang strings array entry can only be set if $p_dir is not null - i.e. in a plugin
if( isset( $g_lang_strings[$p_lang] ) ) {
if( isset( $s_custom_messages[$p_lang] ) ) {
// Step 4 - handle merging in custom strings:
// Possible states:
// 4.a - new string format + new custom string format
$g_lang_strings[$p_lang] = array_replace( ((array)$g_lang_strings[$p_lang]), (array)$s_messages, (array)$s_custom_messages[$p_lang]);
return;
} else {
$g_lang_strings[$p_lang] = array_replace( ((array)$g_lang_strings[$p_lang]), (array)$s_messages);
}
} else {
// new language loaded
$g_lang_strings[$p_lang] = $s_messages;
if( isset( $s_custom_messages[$p_lang] ) ) {
// 4.a - new string format + new custom string format
$g_lang_strings[$p_lang] = array_replace( ((array)$g_lang_strings[$p_lang]), (array)$s_custom_messages[$p_lang]);
return;
}
}
# this may be loaded multiple times, once per language
}

// 4.b new string format + old custom string format
// 4.c - old string format + old custom string format
if( !isset( $s_messages ) || file_exists( $t_custom_strings ) ) {
$t_vars = get_defined_vars();

foreach( array_keys( $t_vars ) as $t_var ) {
$t_lang_var = preg_replace( '/^s_/', '', $t_var );
if( $t_lang_var != $t_var ) {
$g_lang_strings[$p_lang][$t_lang_var] = $$t_var;
}
else if( 'MANTIS_ERROR' == $t_var ) {
if( isset( $g_lang_strings[$p_lang][$t_lang_var] ) ) {
foreach( $$t_var as $key => $val ) {
$g_lang_strings[$p_lang][$t_lang_var][$key] = $val;
}
} else {
$g_lang_strings[$p_lang][$t_lang_var] = $$t_var;
$t_vars = get_defined_vars();

foreach( array_keys( $t_vars ) as $t_var ) {
$t_lang_var = preg_replace( '/^s_/', '', $t_var );
if( $t_lang_var != $t_var ) {
$g_lang_strings[$p_lang][$t_lang_var] = $$t_var;
}
else if( 'MANTIS_ERROR' == $t_var ) {
if( isset( $g_lang_strings[$p_lang][$t_lang_var] ) ) {
foreach( $$t_var as $key => $val ) {
$g_lang_strings[$p_lang][$t_lang_var][$key] = $val;
}
} else {
$g_lang_strings[$p_lang][$t_lang_var] = $$t_var;
}
}
// 4.d old string format + new custom string format
// merge new custom strings into array in same way we merge in 4.a
if( isset( $s_custom_messages[$p_lang] ) ) {
$g_lang_strings[$p_lang] = array_replace( ((array)$g_lang_strings[$p_lang]), (array)$s_custom_messages[$p_lang]);
}
}
}

Expand Down Expand Up @@ -231,7 +192,7 @@ function lang_ensure_loaded( $p_lang ) {
*/
function lang_language_exists( $p_lang ) {
$t_valid_langs = config_get( 'language_choices_arr' );
$t_valid = ( 'english' == $p_lang || in_array( $p_lang, $t_valid_langs, true ) );
$t_valid = in_array( $p_lang, $t_valid_langs, true );
return $t_valid;
}

Expand Down Expand Up @@ -305,10 +266,9 @@ function lang_get_current() {
* 2. The string in English
* @param string $p_string
* @param string $p_lang
* @param bool $p_error default: true - error if string not found
* @return string
*/
function lang_get( $p_string, $p_lang = null, $p_error = true ) {
function lang_get( $p_string, $p_lang = null ) {
global $g_lang_strings;

# If no specific language is requested, we'll
Expand All @@ -324,37 +284,31 @@ function lang_get( $p_string, $p_lang = null, $p_error = true ) {
// Now we'll make sure that the requested language is loaded
lang_ensure_loaded( $t_lang );

// Step 1 - see if language string exists in requested language
# note in the current implementation we always return the same value
# because we don't have a concept of falling back on a language. The
# language files actually *contain* English strings if none has been
# defined in the correct language
# @todo thraxisp - not sure if this is still true. Strings from last language loaded
# may still be in memeory if a new language is loaded.

if( lang_exists( $p_string, $t_lang ) ) {
return $g_lang_strings[$t_lang][$p_string];
} else {
// Language string doesn't exist in requested language

// Step 2 - See if language string exists in current plugin
$t_plugin_current = plugin_get_current();
if( !is_null( $t_plugin_current ) ) {
// Step 3 - Plugin exists: load language file
lang_load( $t_lang, config_get( 'plugin_path' ) . $t_plugin_current . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR );
if( lang_exists( $p_string, $t_lang ) ) {
return $g_lang_strings[$t_lang][$p_string];
}

// Step 4 - Localised language entry didn't exist - fallback to english for plugin
lang_load( 'english', config_get( 'plugin_path' ) . $t_plugin_current . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR );
if( lang_exists( $p_string, $t_lang ) ) {
return $g_lang_strings[$t_lang][$p_string];
}
}

// Step 5 - string didn't exist, try fall back to english:
if( $t_lang == 'english' ) {
if( $p_error ) {
error_parameters( $p_string );
trigger_error( ERROR_LANG_STRING_NOT_FOUND, WARNING );
}
error_parameters( $p_string );
trigger_error( ERROR_LANG_STRING_NOT_FOUND, WARNING );
return '';
} else {
// if string is not found in a language other than english, then retry using the english language.

# if string is not found in a language other than english, then retry using the english language.
return lang_get( $p_string, 'english' );
}
}
Expand Down
20 changes: 11 additions & 9 deletions lang/strings_afrikaans.txt
Expand Up @@ -15,18 +15,26 @@
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* Language File
* See the qqq 'language' for message documentation incl. usage of parameters
* Language File - Afrikaans (Afrikaans)
*
* **********************************************************************
* ** This file is generated from translations stored in translatewiki **
* ** Information on Copyright/License for translatewiki translations **
* ** is available at http://translatewiki.net/wiki/Project:About **
* **********************************************************************
* ** **
* ** DO NOT UPDATE MANUALLY **
* ** **
* ** To improve a translation please visit http://translatewiki.net **
* ** Detailed instructions on how to create or update translations at **
* ** http://www.mantisbt.org/wiki/doku.php/mantisbt:translationshowto **
* **********************************************************************
*
* See the qqq 'language' for message documentation incl. usage of parameters
*
* @ingroup Language
* @copyright Copyright (C) 2002 - 2013 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @file
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/

Expand All @@ -53,7 +61,6 @@ $s_jump_to_bugnotes = 'Spring na Opmerkings';
$s_access_level_project = 'Projek toegangsvlakke';
$s_assigned_projects = 'Toegekende projekte';
$s_assigned_projects_label = 'Toegekende projekte:';
$s_unassigned_projects_label = 'Nie-toegekende projekte:';
$s_print = 'Druk';
$s_jump = 'Spring na';
$s_copy_users = 'Kopieer gebruikers';
Expand Down Expand Up @@ -322,7 +329,6 @@ $s_plugin_actions = 'Aksies';
$s_plugin_install = 'Installeer';
$s_plugin_upgrade = 'Opgradeer';
$s_plugin_uninstall = 'Deïnstalleer';
$s_plugin_key_label = 'Sleutel:';
$s_project_delete_button = 'Verwyder projek';
$s_edit_project_title = 'Wysig projek';
$s_project_name = 'Projeknaam';
Expand Down Expand Up @@ -416,7 +422,6 @@ $s_show_label = 'Wys:';
$s_changed = 'Opgedateer (ure)';
$s_changed_label = 'Opgedateer (ure):';
$s_updated = 'Opgedateer';
$s_sort_label = 'Sorteer op:';
$s_none = 'geen';
$s_search = 'Soek';
$s_view_prev_link = 'Vorige';
Expand All @@ -425,8 +430,6 @@ $s_prev = 'Vorige';
$s_next = 'Volgende';
$s_first = 'Eerste';
$s_last = 'Laaste';
$s_start_date_label = 'Begindatum:';
$s_end_date_label = 'Einddatum:';
$s_yes = 'Ja';
$s_no = 'Nee';
$s_ok = 'OK';
Expand Down Expand Up @@ -528,7 +531,6 @@ $MANTIS_ERROR[ERROR_REPORT] = 'Daar was \'n fout in u verslag.';
$MANTIS_ERROR[ERROR_NO_FILE_SPECIFIED] = 'Geen lêer is verskaf nie.';
$MANTIS_ERROR[ERROR_FILE_DISALLOWED] = 'Die lêertipe word nie toegelaat nie.';
$MANTIS_ERROR[ERROR_NO_DIRECTORY] = 'Die gids bestaan nie. Kontroleer asseblief die projek se instellings.';
$MANTIS_ERROR[ERROR_DUPLICATE_FILE] = 'Die lêer bestaan reeds. Verwyder eers die bestaande lêer.';
$MANTIS_ERROR[ERROR_DUPLICATE_PROJECT] = 'Die projek bestaan reeds.';
$MANTIS_ERROR[ERROR_ACCESS_DENIED] = 'Toegang geweier.';
$MANTIS_ERROR[ERROR_LANG_STRING_NOT_FOUND] = 'String %1$s" is nie gevind nie.';
Expand Down
20 changes: 11 additions & 9 deletions lang/strings_amharic.txt
Expand Up @@ -15,18 +15,26 @@
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* Language File
* See the qqq 'language' for message documentation incl. usage of parameters
* Language File - Amharic (አማርኛ)
*
* **********************************************************************
* ** This file is generated from translations stored in translatewiki **
* ** Information on Copyright/License for translatewiki translations **
* ** is available at http://translatewiki.net/wiki/Project:About **
* **********************************************************************
* ** **
* ** DO NOT UPDATE MANUALLY **
* ** **
* ** To improve a translation please visit http://translatewiki.net **
* ** Detailed instructions on how to create or update translations at **
* ** http://www.mantisbt.org/wiki/doku.php/mantisbt:translationshowto **
* **********************************************************************
*
* See the qqq 'language' for message documentation incl. usage of parameters
*
* @ingroup Language
* @copyright Copyright (C) 2002 - 2013 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @file
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/

Expand Down Expand Up @@ -55,7 +63,6 @@ $s_anonymous = ' ስም የሌለው';
$s_jump_to_bugnotes = 'ወደ ማስታወሻ እለፍ';
$s_assigned_projects = 'የተመደበ ፕሮጀክት';
$s_assigned_projects_label = 'የተመደበ ፕሮጀክት:';
$s_unassigned_projects_label = 'ያልተመደበ ፕሮጀክት';
$s_print = 'አትም';
$s_jump = 'መዝለል';
$s_copy_categories_from = 'የፈርጅ ቅጂ ከ';
Expand Down Expand Up @@ -291,8 +298,6 @@ $s_select_project_button = 'ፕሮጀክት ምረጥ';
$s_lost_password_title = 'የይለፍ ቃሉን እንደገና አስተካክል';
$s_lost_password_done_title = 'የይለፍ ቃሉ መልዕክት ተልኮዋል';
$s_lost_password_subject = 'የይለፍ ቃሉን እንደገና አስተከክል';
$s_open_and_assigned_to_me_label = 'ለእኔ የተከፈተና የተመደበ';
$s_open_and_reported_to_me_label = 'በእኔ የተከፈተና ሪፖርት የተደረገ';
$s_newer_news_link = 'አዲስ ዜናዎች';
$s_older_news_link = 'የቆዩ ዜናዎች';
$s_archives = 'መዝገቦች';
Expand Down Expand Up @@ -336,7 +341,6 @@ $s_changed = 'የተቀየረ(ሰዓት) :';
$s_changed_label = 'የተቀየረ(ሰዓት) :';
$s_viewing_bugs_title = 'ጉዳዩን በመመልከት ላይ';
$s_updated = 'የዘመነ';
$s_sort_label = 'የተደረደረው በ :';
$s_issue_id = 'ጉዳይ #';
$s_recently_visited = 'በቅርብ የተጎበኘ';
$s_note_user_id_label = 'ማስታወሻ በ :';
Expand All @@ -349,8 +353,6 @@ $s_prev = 'የበፊት';
$s_next = 'ቃጣይ';
$s_first = 'መጀመሪያ';
$s_last = 'መጨረሻ';
$s_start_date_label = 'የመጀመሪያ ቀን :';
$s_end_date_label = 'የመጨረሻው ቀን :';
$s_yes = 'አዎ';
$s_no = 'አይ';
$s_or_unassigned = 'ወይም ያልተመደበ';
Expand Down
23 changes: 11 additions & 12 deletions lang/strings_arabic.txt
Expand Up @@ -15,18 +15,26 @@
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* Language File
* See the qqq 'language' for message documentation incl. usage of parameters
* Language File - Arabic (العربية)
*
* **********************************************************************
* ** This file is generated from translations stored in translatewiki **
* ** Information on Copyright/License for translatewiki translations **
* ** is available at http://translatewiki.net/wiki/Project:About **
* **********************************************************************
* ** **
* ** DO NOT UPDATE MANUALLY **
* ** **
* ** To improve a translation please visit http://translatewiki.net **
* ** Detailed instructions on how to create or update translations at **
* ** http://www.mantisbt.org/wiki/doku.php/mantisbt:translationshowto **
* **********************************************************************
*
* See the qqq 'language' for message documentation incl. usage of parameters
*
* @ingroup Language
* @copyright Copyright (C) 2002 - 2013 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @file
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/

Expand Down Expand Up @@ -588,11 +596,6 @@ $s_plugin_install = 'تنصيب';
$s_plugin_upgrade = 'ترقية';
$s_plugin_uninstall = 'فك التنصيب';
$s_plugin_uninstall_message = 'هل أنت متأكد أنك تريد إزالة الإضافة "%1$s"؟';
$s_plugin_key_label = 'المفتاح:';
$s_plugin_key_met = 'الإضافة جاهزة';
$s_plugin_key_unmet = 'اعتمادات غير مقابلة';
$s_plugin_key_dated = 'اعتمادات قديمة';
$s_plugin_key_upgrade = 'الترقية مطلوبة';
$s_project_added_msg = 'المشروع تمت إضافته بنجاح...';
$s_category_added_msg = 'التصنيف تمت إضافته بنجاح...';
$s_category_deleted_msg = 'التصنيف تم حذفه بنجاح...';
Expand Down Expand Up @@ -812,7 +815,6 @@ $s_changed = 'تغيرت(ساعات)';
$s_viewing_bugs_title = 'عرض القضايا';
$s_updated = 'تم التحديث';
$s_sticky = 'عرض القضايا اللاصقة';
$s_sort_label = 'رتب بواسطة:';
$s_issue_id = 'القضية #';
$s_recently_visited = 'المزارة حديثا';
$s_priority_abbreviation = 'P';
Expand All @@ -825,8 +827,6 @@ $s_prev = 'سابق';
$s_next = 'تالي';
$s_first = 'أول';
$s_last = 'آخر';
$s_start_date_label = 'تاريخ البدء:';
$s_end_date_label = 'تاريخ الانتهاء:';
$s_use_date_filters = 'استخدم فلاتر التاريخ';
$s_yes = 'نعم';
$s_no = 'لا';
Expand Down Expand Up @@ -1109,7 +1109,6 @@ $MANTIS_ERROR[ERROR_REPORT] = 'كان هناك خطأ في تقريرك.';
$MANTIS_ERROR[ERROR_NO_FILE_SPECIFIED] = 'لا ملف تم تحديده';
$MANTIS_ERROR[ERROR_FILE_DISALLOWED] = 'نوع الملف غير مسموح به';
$MANTIS_ERROR[ERROR_NO_DIRECTORY] = 'المجلد غير موجود. من فضلك تحقق من إعدادات المشروع.';
$MANTIS_ERROR[ERROR_DUPLICATE_FILE] = 'هذا ملف مكرر. من فضلك احذف الملف أولا.';
$MANTIS_ERROR[ERROR_DUPLICATE_PROJECT] = 'هناك مشروع بهذا الاسم بالفعل.';
$MANTIS_ERROR[ERROR_EMPTY_FIELD] = 'حقل ضروري "%1$s" كان فارغا. من فضلك تحقق مرة أخرى من مدخلاتك.';
$MANTIS_ERROR[ERROR_PROTECTED_ACCOUNT] = 'هذا الحساب محمي. أنت غير مسموح لك بالدخول إلى هذا حتى يتم رفع حماية الحساب.';
Expand Down

0 comments on commit 8863144

Please sign in to comment.