___() function on mozilla.com has broken fallback to en-US

RESOLVED FIXED

Status

www.mozilla.org
General
RESOLVED FIXED
10 years ago
6 years ago

People

(Reporter: pascalc, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

10 years ago
the ___($str) function was taken from mozilla-europe.org code and its purpose is to return a localized string for the english string we provide or fall back to English if the string does not exist. It is mainly used in places like headers, footers and the download box like that:

echo ___('product');

This fallback mechanism does not work on mozilla.com because templates use the HereDoc syntax and we can only include variables in it, not function calls, so what is done currently is that we just don't have a fallback to English and directly call the variable in the array:


$footer 	= <<<FOOTER
  <a href="/{$lang}/about/legal.html">{$GLOBALS['__l10n_moz']['Legal Notices']}</a>
FOOTER;

which generates for locales:
<a href="/fr/about/legal.html"></a>

instead of:
<a href="/fr/about/legal.html">Legal Notices</a>

I propose that we create a small class to work around that problem, I think that the following should work:

class l10nString
{

 var $str;

 public function __construct($str) {

  (!empty($GLOBALS['__l10n_moz'][$str])) ? $this -> str = $GLOBALS['__l10n_moz'][$str] : $this -> str = $str;

 }

}

$foo = new l10nString('Legal Notices');

$footer 	= <<<FOOTER
  <a href="/{$lang}/about/legal.html">{$foo -> str}</a>
FOOTER;

Wil, what do you think of it?
sgarrity pointed this out to me a couple weeks ago and I had a half a patch written for the footer before I realized it wouldn't work. :(

I don't think we need to declare a new object for every string though.  Why not just add a get() function to l10n_moz?
(Reporter)

Comment 2

10 years ago
either that or we use an array instead of a string for the class variable and  we just add strings in the array and call them as $foo -> str[0]
Fix for this is in r14199.  We're using {$l10n->get('variable')}.  Big-ups to oremj for the idea.
Status: NEW → RESOLVED
Last Resolved: 10 years ago
Resolution: --- → FIXED

Updated

10 years ago
Duplicate of this bug: 377530
(Assignee)

Updated

6 years ago
Component: www.mozilla.org/firefox → www.mozilla.org
Product: Websites → Websites
(Assignee)

Updated

6 years ago
Component: www.mozilla.org → General
Product: Websites → www.mozilla.org
You need to log in before you can comment on or make changes to this bug.