Skip to content

Commit

Permalink
[FIX #22 #38] tente de fournir une procédure pour les traduction
Browse files Browse the repository at this point in the history
  • Loading branch information
luffah committed Oct 20, 2018
1 parent fa00353 commit d9911ca
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 19 deletions.
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _ensure_dir_build:
_js_transpile: _ensure_dir_build
${NODEJS} ./node_modules/.bin/babel \
-o _build/all.${_LANG}.js --presets env \
`grep '<script ' ./src/index.html | egrep -v 'tests/|<!--|-->' | sed 's/.*src="\([^"]*.js\)".*/.\/src\/\1/;s/${LANG_REGEX}/\1${_LANG}\2/'`
`grep '<script ' ./src/index.html | grep 'src=' | egrep -v 'tests/|<!--|-->' | sed 's/.*src="\([^"]*.js\)".*/.\/src\/\1/;s/${LANG_REGEX}/\1${_LANG}\2/'`

_js: _js_transpile
${NODEJS} ./node_modules/.bin/uglifyjs \
Expand All @@ -37,9 +37,13 @@ js: .npm po ## Compress javascript files
_LANG=$${_LANG} make _js; \
done

po: ## Generate javascript file from pofile
_check_polib:
${PYTHON} -c "import polib" || pip install polib

_ensure_js_build_dir:
mkdir -p ./src/js/_build
which pip && ( pip search polib || pip install polib)

po: _ensure_js_build_dir _check_polib ## Generate javascript files from pofiles
find ./src/lang -name '*.po' | sed 's/^.*\.\([A-Za-z-]\+\)\.po/\1/' \
| while read i; do ${PYTHON} ./buildsystem/po2json.py $${i}; done;

Expand All @@ -56,6 +60,12 @@ assets: ## Place images and sounds in webroot dir
cp src/snd/*.wav webroot/snd/;

# EXTRA #
pot: _ensure_js_build_dir _check_polib ## Generate a pot file from a pofile [usage: _LANG=xx make pot]
${PYTHON} ./buildsystem/potgenfromlang.py $(or ${_LANG}, fr)

translatorguide: ## A little guide for new translators
less src/lang/README

to_dokuwiki: ## Convert markdown files in wiki_md to wiki_dokuwiki
find ./wiki_md -name '*.md' | \
while read i; do \
Expand Down
18 changes: 9 additions & 9 deletions buildsystem/po2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
LANG = sys.argv[1]
APP_NAME = 'terminus'
ORIG = ('./src/lang/%s.%s.po' % (APP_NAME, LANG))
TGT = ('./src/js/_build/%s.dialog.%s.js' % (APP_NAME, LANG))
TGT = ('./src/js/_build/%s.dialog.%s.js' % (APP_NAME, LANG))

po = polib.pofile(ORIG)
if not po:
Expand All @@ -16,17 +16,17 @@
f.write("var dialog={")
for entry in po:
if len(entry.msgid.split("\n")) > 2:
msgid=('"%s"') % entry.msgid.replace('"','\"')
msgid = ('"%s"') % entry.msgid.replace('"', '\"')
else:
msgid = entry.msgid.replace("\n","")
msgid = entry.msgid.replace("\n", "")
if " " in msgid:
msgid=('"%s"') % msgid.replace('"','\\"')
msgid = ('"%s"') % msgid.replace('"', '\\"')
msgstr = entry.msgstr.replace(
'\\','\\\\').replace(
'\\"','\\\\"').replace(
"\n","\\n").replace(
'"','\\"')
'\\', '\\\\').replace(
'\\"', '\\\\"').replace(
"\n", "\\n").replace(
'"', '\\"')

f.write('%s:"%s",\n'%(msgid,msgstr))
f.write('%s:"%s",\n' % (msgid, msgstr))
f.write("};")
f.write("const APP_NAME='%s';const LANG='%s';" % (APP_NAME, LANG))
27 changes: 27 additions & 0 deletions buildsystem/potgenfromlang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
import re
import sys
import polib

LANG = sys.argv[1]
APP_NAME = 'terminus'
ORIG = ('./src/lang/%s.%s.po' % (APP_NAME, LANG))
TGT = ('./src/lang/%s.pot' % APP_NAME)

po = polib.pofile(ORIG)
if not po:
exit(1)

pot = polib.POFile()
pot.metadata = po.metadata
for entry in po:
if not entry.comment:
com = entry.msgstr
if len(com.split("\n")) > 2 and not re.match(r".*({{|%s)", com):
com = "\n".join(com.split("\n")[0:2]) + " ..."
entry.comment = '[%s] "%s"' % (LANG,
com.replace("\n",'\\n').replace('"','\\"'))
entry.msgstr = ''
pot.append(entry)

pot.save(TGT)
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
| [Français](./readme.fr.md) | | [English](./readme.en.md) |
| :--- | - | :--- |
| Dans un univers où la magie a été remplacée par le mystérieux pouvoir de la ligne de commande, vous incarnez un personnage démuni qui n'aura d'autre choix que d'en servir pour reprendre le contrôle de sa vie. [>> wiki](https://github.com/luffah/Terminus/wiki) [>> install](./readme.fr.md)|| In a mysterious land, both physical and magical powers had been surpassed by a new power : the command line. Lost somewhere in this land, you discover that you could use this power without knowing how. [>> wiki (not available)](https://github.com/luffah/Terminus/wiki/Home.en) [>> install](./readme.en.md) |

## Note for translator and developer
Use `make`.
5 changes: 3 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
<!-- main elements -->
<span id="rubandev">beta</span>
<div id="term"></div>
<!--<iframe id="pogen" style="display:none;"></iframe>-->

<!-- lang data -->
<script type="text/javascript" src="./js/_build/terminus.dialog.fr.js"></script>
<!-- scripts -->
<!--<iframe id="pogen" style="display:none;"></iframe>-->
<script type="text/javascript" src="./js/engine/seq.js"></script>
<script type="text/javascript" src="./js/engine/dom.js"></script>
<script type="text/javascript" src="./js/engine/random.js"></script>
<script type="text/javascript" src="./js/engine/object.js"></script>
<script type="text/javascript" src="./js/engine/string.js"></script>
<script type="text/javascript" src="./js/engine/array.js"></script>
<script type="text/javascript" src="./js/background.js"></script>
<script type="text/javascript" src="./js/_build/terminus.dialog.fr.js"></script>
<script type="text/javascript" src="./js/engine/lang/pogen.js"></script>
<script type="text/javascript" src="./js/engine/lang/Gettext.js"></script>
<script type="text/javascript" src="./js/engine/state/Cookie.js"></script>
Expand Down
3 changes: 3 additions & 0 deletions src/js/terminus.gamestart.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ window.addEventListener('load', Game)
function Game(){
var t = Game.prototype
t.version = '0.2beta'
newRoom('home', undefined, {writable: true })
loadLevel1()
loadLevel2()
if (typeof doTest === 'function') {
doTest(vt)
return
Expand Down
4 changes: 2 additions & 2 deletions src/js/terminus.level1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// mkdir('/home/$USER',)
// mkfile('~/shell')
// mkdir('~/western_forest')
newRoom('home', undefined, {writable: true })

function loadLevel1(){
$home.setEnterCallback(function () {
vt.playMusic('forest')
})
Expand Down Expand Up @@ -258,5 +258,5 @@ var rat = $tunnel
rat.setTextIdx(rat_txtidx++)
}
})

}
// ---------------END LEVEL 1-----------------
3 changes: 2 additions & 1 deletion src/js/terminus.level2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

//---------------LEVEL 2---------------------
//TOWN SQUARE
function loadLevel2(){
$portal.addPath(
newRoom("townsquare", "loc_square.gif")
);
Expand Down Expand Up @@ -398,4 +399,4 @@ $morekernel.newItem('bigfile', null, {povars: ['T']}).setCmd('grep',(args)=>{
//PARADISE (end game screen)
newRoom("paradise", "loc_theend.gif")
.setCmd("ls", _('room_paradise_ls'));

}
40 changes: 40 additions & 0 deletions src/lang/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# TRANSLATOR GUIDE

If your are a new translator, just read next lines.

There is 2 way to submit corrections and translations :

## the lazy one

* PROS : fast
* CONS : you will not see the change before a moment

Edit directly terminus.LANG.po in the git Web interface

Saving will create a pull request to the repository owner who
will have to compile.


## the hard one

* PROS : you can test the modification
* CONS : you'll have to install python3 with polib

Clone the git repository.

If you need to add a language file,
you can do `make pot`(or `make pot _LANG=fr`)
and copy terminus.pot to terminus.LANG.pox.

Edit terminus.LANG.po

Then do `make po`.

In order to test, without installing nodejs,
you can open `testlang.html` in a browser adding `?LANG`.

URL exemple : file:///home/user/terminus/src/testlang.html?en




4 changes: 2 additions & 2 deletions src/testing.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
var __xhr = new XMLHttpRequest()
__xhr.open("GET","index.html")
__xhr.setRequestHeader('Content-type',
'application/x-www-form-urlencoded; charset=utf-8;');
'application/x-www-form-urlencoded; charset=utf-8;')
__xhr.onreadystatechange = function(){
if (__xhr.readyState == 4 && __xhr.status == 200) {
__el.innerHTML=__xhr.responseText
__body = __el.getElementsByTagName('body')[0]
__tests.forEach((t) => {
let node = document.createElement('script')
node.type = "text/javascript";
node.type = "text/javascript"
node.setAttribute('src', t)
__body.appendChild(node)
})
Expand Down
29 changes: 29 additions & 0 deletions src/testlang.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE HTML>
<html>
<head id='head'>
<meta charset="utf-8" />
<script>
var __xhr = new XMLHttpRequest()
__xhr.open("GET","index.html")
__xhr.setRequestHeader('Content-type',
'application/x-www-form-urlencoded; charset=utf-8;')

__xhr.onreadystatechange = function(){
if (__xhr.readyState == 4 && __xhr.status == 200) {
var content =
document.open()
document.write(__xhr.responseText)
document.close()
var __lang=window.location.search.substr(1)
if (__lang){
let node = document.createElement('script')
node.type = "text/javascript"
node.setAttribute('src', './js/_build/terminus.dialog.'+__lang+'.js')
document.body.appendChild(node)
}
}
}
__xhr.send()
</script>
</head>
</html>

0 comments on commit d9911ca

Please sign in to comment.