Skip to content
Browse files

Added localization support

  • Loading branch information...
1 parent b07fd5e commit 721de4403f41d0b6a11af12af97cb8f60928a2f5 @peroo peroo committed Feb 24, 2012
Showing with 53 additions and 9 deletions.
  1. +3 −1 index.html
  2. +19 −0 js/l11n.js
  3. +1 −1 js/options.js
  4. +10 −0 locales/en/localestrings.js
  5. +15 −6 options.html
  6. +5 −1 style/options.css
View
4 index.html
@@ -9,6 +9,8 @@
</head>
<body>
<header><h1>News Portal</h1></header>
- <div id=content><h2>Loading...</h2></div>
+ <div id=content><h2><span class=l11n>Loading</span>...</h2></div>
+ <script src="localestrings.js"></script>
+ <script src="js/l11n.js"></script>
</body>
</html>
View
19 js/l11n.js
@@ -0,0 +1,19 @@
+(function()
+{
+ var nodes = document.getElementsByClassName('l11n');
+ for(var i=0, node; node = nodes[i]; i++) {
+ var key = node.textContent;
+ if(_STRINGS[key]) {
+ node.textContent = _STRINGS[key];
+ }
+ }
+
+ window._getString = function(name) {
+ if(_STRINGS[name]) {
+ return _STRINGS[name];
+ }
+ else {
+ return name;
+ }
+ }
+}());
View
2 js/options.js
@@ -67,7 +67,7 @@
for (var i = 0, source; source = allSources[i]; i++) {
options += '<option value="' + source.box_title + '">' + source.box_title + '</option>';
}
- sourceHTML = '<td><select>'+options+'</select></td><td><label><span><input type="number" step="1" min="1" max="3"></span><span>posts</span></label></td><td><button class="minus"><span>-</span></button><button class="plus"><span>+</span></button></td>';
+ sourceHTML = '<td><select>'+options+'</select></td><td><label><span><input type="number" step="1" min="1" max="3"></span><span>' + _getString('posts') + '</span></label></td><td><button class="minus"><span>-</span></button><button class="plus"><span>+</span></button></td>';
document.getElementsByName('secondsperpost')[0].value = widget.preferences['delay'];
document.getElementsByTagName('form')[0].addEventListener('submit', save, false);
for (var a = 0; a < sources.length; a++) {
View
10 locales/en/localestrings.js
@@ -0,0 +1,10 @@
+_STRINGS = {
+ "Loading": null,
+ "Seconds Per Post": null,
+ "seconds": null,
+ "Sources": null,
+ "posts": null,
+ "Save": null,
+ "Note": null,
+ "To change language or add more sources, please go to": null
+}
View
21 options.html
@@ -2,22 +2,22 @@
<html>
<head>
<meta charset="UTF-8">
- <title>Opera Portal - Preferences</title>
+ <title>News Portal - Preferences</title>
<script src=js/options.js></script>
<link rel=stylesheet type=text/css href=style/options.css />
</head>
<body>
-<form name="Opera Portal prefrences">
+<form name="News Portal preferences">
<fieldset>
<table>
<tr>
- <td>Seconds Per Post</td>
- <td><label><span><input type="number" name="secondsperpost" step="1" min="1"></span> <span>seconds</span></label></td>
+ <td class=l11n>Seconds Per Post</td>
+ <td><label><span><input type="number" name="secondsperpost" step="1" min="1"></span> <span class=l11n>seconds</span></label></td>
<td><div>Specifies the amount of time each post displays before transitioning to the next one.</div></td>
</tr>
<tr>
- <td>Sources</td>
+ <td class=l11n>Sources</td>
<td>
<table><tbody id="sources"></tbody></table>
</td>
@@ -29,7 +29,16 @@
</table>
</fieldset>
+ <fieldset>
+ <div id=notice><b class=l11n>Note</b>: <span class=l11n>To change language or add more sources, please go to</span> <a href="http://portal.opera.com">Portal</a>.</div>
+ </fieldset>
+
<fieldset class="buttons">
- <button type="submit">Save</button>
+ <button type="submit" class=l11n>Save</button>
</fieldset>
</form>
+
+<script src="localestrings.js"></script>
+<script src="js/l11n.js"></script>
+</body>
+</html>
View
6 style/options.css
@@ -50,7 +50,7 @@ form
fieldset
{margin-top : 10px;
text-shadow : transparent 0 0 0;}
-fieldset>table
+fieldset>table, #notice
{width : 100%;
border : 1px solid #ababab;
border-radius : 8px;
@@ -218,3 +218,7 @@ button
{width : 100%;}
}
+#notice {
+ width: 94%;
+ padding: 0.5em 3%;
+}

0 comments on commit 721de44

Please sign in to comment.
Something went wrong with that request. Please try again.