From c63adcfae061809ce25217207f638b1e6c1d1bee Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 21 Sep 2011 07:09:37 -0700 Subject: bug #159 multiple definition of string_plural_form function when changing languages --- include/pgettext.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'include/pgettext.php') diff --git a/include/pgettext.php b/include/pgettext.php index 49f100737..c7fc58698 100644 --- a/include/pgettext.php +++ b/include/pgettext.php @@ -90,8 +90,11 @@ if(! function_exists('load_translation_table')) { function load_translation_table($lang) { global $a; - if(file_exists("view/$lang/strings.php")) + if(file_exists("view/$lang/strings.php")) { include("view/$lang/strings.php"); + } + else + $a->strings = array(); }} // translate string if translation exists @@ -110,12 +113,13 @@ function t($s) { if(! function_exists('tt')){ function tt($singular, $plural, $count){ - + global $lang; $a = get_app(); if(x($a->strings,$singular)) { $t = $a->strings[$singular]; - $k = string_plural_select($count); + $f = 'string_plural_select_' . str_replace('-','_',$lang); + $k = $f($count); return is_array($t)?$t[$k]:$t; } -- cgit v1.2.3 From 030e1e82c32a3061abf71ffb90e65f2b9197d8a4 Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 21 Sep 2011 15:37:16 -0700 Subject: finish up ability to switch languages without function collision --- include/pgettext.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include/pgettext.php') diff --git a/include/pgettext.php b/include/pgettext.php index c7fc58698..83e76ba9d 100644 --- a/include/pgettext.php +++ b/include/pgettext.php @@ -119,6 +119,8 @@ function tt($singular, $plural, $count){ if(x($a->strings,$singular)) { $t = $a->strings[$singular]; $f = 'string_plural_select_' . str_replace('-','_',$lang); + if(! function_exists($f)) + $f = 'string_plural_select_default'; $k = $f($count); return is_array($t)?$t[$k]:$t; } @@ -128,4 +130,13 @@ function tt($singular, $plural, $count){ } else { return $singular; } -}} \ No newline at end of file +}} + +// provide a fallback which will not collide with +// a function defined in any language file + +if(! function_exists('string_plural_select_default')) { +function string_plural_select_default($n) { + return ($n != 1); +}} + -- cgit v1.2.3