Started localization work.

This commit is contained in:
Thomas Wilburn 2014-06-29 18:16:50 -07:00
parent b91b9a06a4
commit 3d3a916fe8
8 changed files with 55 additions and 11 deletions

View file

@ -40,6 +40,7 @@ module.exports = function(grunt) {
},
copy: [
"config/**",
"_locales/**",
"js/**",
"css/*.css",//leave the LESS behind
"**/*.html",//both main.html and the templates

17
_locales/en/messages.json Normal file
View file

@ -0,0 +1,17 @@
{
"loading": {
"message": "loading"
},
"aboutWrittenBy": {
"message": "Written by <a href=\"http://thomaswilburn.net\" target=_blank>Thomas Wilburn</a>"
},
"aboutHomePage": {
"message": "Home Page"
},
"aboutSupport": {
"message": "Support"
},
"aboutLicense": {
"message": "Caret is available under a GPL license, which means that the <a href=\"https://github.com/thomaswilburn/Caret\" target=_blank>source code</a> is freely available for you to use and modify as you see fit. If you find Caret useful, consider donating to the Free Software Foundation's <a href=\"https://my.fsf.org/donate/directed-donations/esp\" target=_blank>Fund to End Software Patents</a>."
}
}

View file

@ -6,6 +6,7 @@ require([
"ui/dialog",
"sessions",
"util/manos",
"util/i18n",
"ui/projectManager",
"ui/keys",
"fileManager",
@ -14,7 +15,10 @@ require([
"ui/cli",
"api",
"storage/syncfile"
], function(command, Settings, dialog, sessions, M) {
], function(command, Settings, dialog, sessions, M, i18n) {
//translate inline strings
i18n.page();
var frame = chrome.app.window.current();
@ -33,8 +37,8 @@ require([
//these are modules that must be loaded before init:complete
var loadedModules = {
"editor": false,
"fileManager": false,
"editor": false,
"fileManager": false,
"sessions": false
};

20
js/util/i18n.js Normal file
View file

@ -0,0 +1,20 @@
define(["util/dom2"], function() {
return {
//process a chunk of template HTML for i18n strings
process: function(html) {
return html.replace(/__MSG_(\w+)__/g, function(match, tag) {
return chrome.i18n.getMessage(tag);
});
},
//process the page for inline strings, marked with .i18n
page: function() {
document.findAll(".i18n").forEach(function(element) {
var original = element.innerHTML;
var translated = chrome.i18n.getMessage(original);
if (translated) element.innerHTML = translated;
});
}
}
});

View file

@ -1,6 +1,7 @@
define([
"util/i18n",
"util/dom2"
], function() {
], function(i18n) {
/*
@ -102,7 +103,7 @@ define([
var load = function(path) {
return new Promise(function(ok) {
require(["util/text!" + path], function(text) {
cache[path] = text;
cache[path] = i18n.process(text);
ok();
});
});

View file

@ -22,7 +22,7 @@
<div class="project">
<div class="tree"></div>
<div class="load-ui">
loading
<span class="i18n">loading</span>
<div class="progress"></div>
</div>
</div>

View file

@ -3,6 +3,7 @@
"description": "Professional text editing for Chrome and Chrome OS",
"version": "1.4.19",
"manifest_version": 2,
"default_locale": "en",
"icons": {
"128": "icon-128.png"
},

View file

@ -1,11 +1,11 @@
<div><span class="credits">
<h2>Caret v.{{version}}</h2>
<ul>
<li>Written by <a href="http://thomaswilburn.net" target=_blank>Thomas Wilburn</a>
<li>
<a href="http://thomaswilburn.net/caret" target=_blank>[ Home Page ]</a>
<li>__MSG_aboutWrittenBy__
<li>
<a href="http://thomaswilburn.net/caret" target=_blank>[ __MSG_aboutHomePage__ ]</a>
&mdash;
<a href="https://chrome.google.com/webstore/support/fljalecfjciodhpcledpamjachpmelml#bug" target=_blank>[ Support ]</a>
<li>Caret is available under a GPL license, which means that the <a href="https://github.com/thomaswilburn/Caret" target=_blank>source code</a> is freely available for you to use and modify as you see fit. If you find Caret useful, consider donating to the Free Software Foundation's <a href="https://my.fsf.org/donate/directed-donations/esp" target=_blank>Fund to End Software Patents</a>.
<a href="https://chrome.google.com/webstore/support/fljalecfjciodhpcledpamjachpmelml#bug" target=_blank>[ __MSG_aboutSupport__ ]</a>
<li>__MSG_aboutLicense__
</ul>
</span></div>