fabi1cazenave / webL10n

Client-side internationalization / localization library
http://fabi1cazenave.github.com/webL10n/
278 stars 70 forks source link

Support = in locale files #10

Closed clochix closed 12 years ago

clochix commented 12 years ago

I wanted to use innerHTML 

duck = run <a href="http://duck.net">baby</a>

But you use = to split the string, so everything after href is lost.

Here's a quick fix proposal:

git diff --no-prefix

diff --git l10n.js l10n.js
index 3be588a..2924727 100644
--- l10n.js
+++ l10n.js
@@ -127,7 +127,7 @@ document.webL10n = (function(window, document, undefined) {
       var reComment = /^\s*#|^\s*$/;
       var reSection = /^\s*\[(.*)\]\s*$/;
       var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
-      var reSplit = /\s*=\s*/; // TODO: support backslashes to escape EOLs
+      var reSplit = /^([^=\s]*)\s*=\s*(.+)$/; // TODO: support backslashes to escape EOLs

       // parse the *.properties file into an associative array
       function parseRawLines(rawText, extendedSyntax) {
@@ -162,9 +162,9 @@ document.webL10n = (function(window, document, undefined) {
           }

           // key-value pair
-          var tmp = line.split(reSplit);
-          if (tmp.length > 1)
-            dictionary[tmp[0]] = evalString(tmp[1]);
+          var tmp = line.match(reSplit);
+          if (tmp.length === 3)
+            dictionary[tmp[1]] = evalString(tmp[2]);
         }
       }
fabi1cazenave commented 12 years ago

agreed, thanks! WIP.

fabi1cazenave commented 12 years ago

solved with the latest commit, thanks again