-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from gameclosure/feature-trans
Feature trans
- Loading branch information
Showing
7 changed files
with
199 additions
and
10 deletions.
There are no files selected for viewing
Submodule squill
updated
from 5dee26 to 42a2ac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"version": "0.1.0", | ||
"author": "Game Closure", | ||
"name": "Internationalization", | ||
"scope": "i18n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** @license | ||
* This file is part of the Game Closure SDK. | ||
* | ||
* The Game Closure SDK is free software: you can redistribute it and/or modify | ||
* it under the terms of the Mozilla Public License v. 2.0 as published by Mozilla. | ||
* The Game Closure SDK is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Mozilla Public License v. 2.0 for more details. | ||
* You should have received a copy of the Mozilla Public License v. 2.0 | ||
* along with the Game Closure SDK. If not, see <http://mozilla.org/MPL/2.0/>. | ||
*/ | ||
|
||
// Internationalization plugin | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var etag = require('../../etag'); | ||
var projectManager = require('../../../ProjectManager'); | ||
|
||
var _app; | ||
|
||
projectManager.on('AddProject', serveProject); | ||
|
||
var _trans = {}; | ||
|
||
function serveProject (project) { | ||
var id = project.getID(); | ||
var langPath = path.join(project.paths.root, 'resources', 'lang'); | ||
|
||
if (_trans[id] || !fs.existsSync(langPath)) { return false; } | ||
|
||
var trans = _trans[id] = {}; | ||
var langs = fs.readdirSync(langPath); | ||
var shouldServe = false; | ||
|
||
for (var i = 0; i < langs.length; i++) { | ||
var fname = langs[i]; | ||
var lparts = fname.split('.'); | ||
if (lparts[0] != 'all' && lparts[1] == 'json') { | ||
shouldServe = true; | ||
trans[lparts[0]] = JSON.parse(fs.readFileSync(path.join(langPath, fname))); | ||
} | ||
} | ||
|
||
if (shouldServe) { | ||
fs.writeFileSync(path.join(langPath, 'all.json'), JSON.stringify(trans)); | ||
_app.use('/simulate/' + id + '/lang/', etag.static(langPath)); | ||
} | ||
} | ||
|
||
exports.load = function (app) { | ||
_app = app; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** @license | ||
* This file is part of the Game Closure SDK. | ||
* | ||
* The Game Closure SDK is free software: you can redistribute it and/or modify | ||
* it under the terms of the Mozilla Public License v. 2.0 as published by Mozilla. | ||
* The Game Closure SDK is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Mozilla Public License v. 2.0 for more details. | ||
* You should have received a copy of the Mozilla Public License v. 2.0 | ||
* along with the Game Closure SDK. If not, see <http://mozilla.org/MPL/2.0/>. | ||
*/ | ||
|
||
import sdkPlugin; | ||
import util.ajax; | ||
import squill.Cell; | ||
import squill.TabbedPane; | ||
import squill.models.DataSource as DataSource; | ||
|
||
var transHowTo = "You haven't set up any translations yet. Add your language-specific json files to resources/lang."; | ||
|
||
var TranslationCell = Class(squill.Cell, function() { | ||
this._def = { | ||
className: 'translationCell', | ||
children: [ | ||
{ | ||
id: 'key', type: 'label', className: 'translationKey' | ||
}, | ||
{ | ||
id: 'value', type: 'label', className: 'translationValue' | ||
} | ||
] | ||
}; | ||
|
||
this.render = function() { | ||
this.key.setLabel(this._data.key); | ||
this.value.setLabel(this._data.value); | ||
}; | ||
}); | ||
|
||
exports = Class(sdkPlugin.SDKPlugin, function(supr) { | ||
this._def = { | ||
children: [ | ||
{ | ||
className: 'topTabs', | ||
id: 'translationTabs', | ||
type: squill.TabbedPane, | ||
panes: [] | ||
} | ||
] | ||
}; | ||
|
||
this.buildTranslations = function(err, trans) { | ||
this.translationTabs.clear(); | ||
if (err) { | ||
this.translationTabs.newPane({ | ||
className: 'mainPanel', | ||
title: 'no translations yet!', | ||
children: [{ | ||
id: 'noTranslations', | ||
text: transHowTo, | ||
style: { padding: '20px' } | ||
}] | ||
}); | ||
} else { | ||
for (var k in trans) { | ||
var ds = new DataSource({ key: 'key' }); | ||
for (var key in trans[k]) { | ||
ds.add({ key: key, value: trans[k][key] }); | ||
} | ||
this.translationTabs.newPane({ | ||
className: 'mainPanel', | ||
title: k, | ||
children: [{ | ||
id: k + 'List', | ||
className: 'darkPanel translationList', | ||
margin: 10, | ||
type: 'list', | ||
controller: this, | ||
cellCtor: TranslationCell, | ||
dataSource: ds | ||
}] | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
this.onBeforeShow = function() { | ||
util.ajax.get({ | ||
url: this._project.url + 'lang/all.json', | ||
type: 'json' | ||
}, bind(this, 'buildTranslations')); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
translationListMargin = 15px | ||
|
||
.translationList | ||
absoluteBox(translationListMargin, translationListMargin, translationListMargin, translationListMargin) | ||
overflow: auto; | ||
|
||
.translationCell | ||
color #EEE | ||
font-size 12px | ||
cursor pointer | ||
border-top 1px solid rgba(0, 0, 0, 0) | ||
border-bottom 1px solid rgba(0, 0, 0, 0) | ||
padding 10px | ||
font-family 'Gill Sans' | ||
|
||
.translationCell:nth-child(even) | ||
background-color rgba(0, 0, 0, 0.4) | ||
|
||
.translationCell .translationKey | ||
color #EEF | ||
text-shadow none | ||
width 320px | ||
font-size 15px | ||
margin 0 | ||
text-align left | ||
|
||
.translationCell .translationKey | ||
.translationCell .translationValue | ||
display inline-block | ||
text-overflow: ellipsis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters