Skip to content

html -> php for add gettext multilingue #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.cvsignore
Thumbs.db
.DS_Store
*.esproj
*.py[co]
_darcs/*
CVS/*
Expand All @@ -30,3 +31,7 @@ node_modules

# Cloud9IDE
.settings.xml

libredocs.esproj/Project.espressostorage

libredocs.esproj/user.benoit.espressostorage
21 changes: 21 additions & 0 deletions closeDialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<head>
<title>Closing dialog...</title>
<meta charset="utf-8">
<script src="js/require.js"></script>
<script>
require(['js/src/remoteStorage'], function(remoteStorage) {
var storageInfo = JSON.parse(localStorage.getItem('_juggleStorageInfo'));
localStorage.removeItem('_juggleStorageInfo');
window.opener.postMessage('conn:'+JSON.stringify({
storageInfo: storageInfo,
bearerToken: remoteStorage.receiveToken()
}), location.protocol+'//'+location.host);
window.close();
});
</script>
</head>
<body>
Closing dialog...
</body>
</html>
24 changes: 18 additions & 6 deletions css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,32 @@ h1 span#docTitle { position:absolute; left:.08em; width:11em; white-space:nowrap
h1+small { float:right; position:relative; top:-2em; right:0em; }
h1>small { font-size:12px; position:absolute; left:16.8em; top:.5em; white-space:nowrap; }

#lang { float:right; position:relative; top:-2em; right:3em; }
#lang li {display: inline-block; text-transform: uppercase; margin: 0 .3em; }


#locale { float: right; margin-top: -3em; }
#locale li { float: left; list-style: none; }
#locale img { padding: 0; margin: 0; height: auto!important; }
#locale li a { padding: 1em .5em.5em; margin: 0; }

#locale a:hover, #locale a.selected { background: rgba(200, 200, 200, 0.7); border-bottom-left-radius: .5em; border-bottom-right-radius: .5em; box-shadow: #fff 0 1px 0; }


#signin { margin-top:5.5em; padding:0 8em 1em 7em; white-space:nowrap; height:2.6em; }
#write #signin { position:relative; float:right; top:1em; margin:0; }
.content #welcome { height:29em; }
.content #welcome { height:32em; }
#steps { position:absolute; top:22em; }
.step, .step.done, .step.done:hover { opacity:.5; position:relative; }
.step.active, .step:hover { opacity:1; }
.step.remotestorage { position:absolute; width:20em; left:0; }
.step.remotestorage img, .step.write img { position:relative; left:20%; }
.step.remotestorage img { margin:2em 0; width:12em; }
.step.connect { position:absolute; width:18em; left:21em; }
.step.connect #connect { position:absolute; width:15em; }
.step.connect #connect-address { position:absolute; margin:4em 0 .5em; width:9.35em; padding-right:6em; height:2.5em; padding-left:3em; background:url('../images/remoteStorage-icon.png') no-repeat .3em center; }
.step.connect #connect-button { position:absolute; margin:4.6em -3em 0 0; right:0; }
.step.write { position:absolute; width:20em; left:41em; }
.step.connect { position:absolute; width:19em; left:23em; }
.step.connect #connect { position:absolute; width:16em; }
.step.connect #connect-address { position:absolute; margin:4em 0 .5em -2em; width:9.35em; padding-right:7em; height:2.5em; padding-left:3em; background:url('../images/remoteStorage-icon.png') no-repeat .3em center; }
.step.connect #connect-button { position:absolute; margin:4.6em -1em 0 0; right:0; }
.step.write { position:absolute; width:18em; left:42em; }
.step.write img { margin-top:-1em; }
.step>h3 { position:absolute; top:7.3em; white-space:nowrap; }
.step>p { position:absolute; top:12.5em; }
Expand Down
39 changes: 0 additions & 39 deletions dialog.html

This file was deleted.

2 changes: 1 addition & 1 deletion documents.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="documents">
<div class="btn" id="new-document"><strong>+ New document</strong></div>
<div class="btn translatable" id="new-document"><strong>+ New document</strong></div>
<input id="upload-document" type="file" multiple></input>
<!-- <div id="trashbox" class='box'>drop an entry to remove</div> -->
<ul id="doclist">
Expand Down
2 changes: 1 addition & 1 deletion goToStep.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</script>
</head>
<body>
<p>Done. Go <a href="welcome.html">back to the main page</a>.</p>
<p>Done. Go <a href="welcome.html">Retour à la page principale</a>.</p>
</body>
</html>
Binary file added images/countries/de.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/countries/en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/countries/fr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/countries/id.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/countries/it.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/countries/ru.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>Write with Libre Docs &ndash; liberate your ideas</title>
<title class="translatable">Write with Libre Docs &ndash; liberate your ideas</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/webodf.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="css/custom.css" rel="stylesheet">
<link rel="shortcut icon" href="images/libredocs.png">
<link rel="apple-touch-icon" href="images/libredocs.png">
<script src="js/require.js"></script>

<script>
require(['js/src/remoteStorage'], function(drop) {
remoteStorage=drop;
Expand All @@ -18,12 +19,17 @@
<script src="js/models/document.js"></script>
<script src="js/sync.js"></script>
<script src="js/init.js"></script>


</head>
<body>

<div class="container">
<div class="page-header" id="header">
<img alt="" src="images/libredocs.png" />
<h1><a href="#">Libre Docs</a> <small>molto alpha</small></h1><small id="signout"></small>

<ul id="locale"><li><span class="translatable">Translation Test</span> || </li></ul>
</div>
<div id="error" class="alert alert-block alert-error fade in" style="display:none;">
<h4 id="error-heading" class="alert-heading"><!-- ERROR HEAD --></h4>
Expand All @@ -36,12 +42,14 @@ <h4 id="error-heading" class="alert-heading"><!-- ERROR HEAD --></h4>
<!-- CONTENT -->
</div>
<footer>
<p><a href="/">Libre Docs</a> is a <a href="https://github.com/unhosted/libredocs">free software</a> app by <a href="http://unhosted.org">Unhosted</a> for a more open web.</p>
<p class="translatable"><a href="/">Libre Docs</a> is a <a href='https://github.com/unhosted/libredocs'>free software</a> app by <a href='http://unhosted.org'>Unhosted</a> for a more open web.</p>
</footer>
</div> <!-- /container -->
<!-- fallback to local, thanks to HTML5 Boilerplate -->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>

<script src="js/load.js"></script>
<script src="js/ieblock.js"></script>
<script src="js/features.js"></script>
Expand All @@ -53,6 +61,10 @@ <h4 id="error-heading" class="alert-heading"><!-- ERROR HEAD --></h4>
<script src="js/bootstrap-modal.js"></script>
<script src="/lib/runtime.js"></script>
<script src="js/etherpad.js"></script>

<!-- Test traduction -->
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script src="js/default.js"></script>

<!-- SCRIPTS -->
</body>
Expand Down
2 changes: 2 additions & 0 deletions js/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


104 changes: 104 additions & 0 deletions js/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
var lp = {"locales":[{"id":"en","name":"english"},{"id":"fr","name":"french"}]};

lp = $.extend(lp, {

/**
* Actual user locale
*/
locale: 'en',

/**
* Translation dictionaries
*/
dictionaries: {},

setLocale: function(locale) {
if (!locale) {
locale = $.cookie('locale');
}
if (!locale) {
locale = window.navigator.language ? window.navigator.language : window.navigator.userLanguage;
}

if (locale != lp.locale) {
$.cookie('locale', locale);
lp.locale = locale;

$.each(lp.locales, function(lidx, availableLocale) {
if (locale.indexOf(availableLocale.id) != -1 || !locale.indexOf(availableLocale.name != -1)) {
$('#locale a').removeClass('selected');
$('#lang-' + availableLocale.id).addClass('selected');
lp.translateTo(availableLocale.id);
}
} );
}
},

getDictionary: function(locale) {
$.getJSON('js/locales/' + locale + '.json', function(dictionary) {
lp.dictionaries[locale] = dictionary;
lp.translateTo(locale);
} );
},

translateTo: function(locale, $from) {
if (!locale) {
return;
}

if (typeof lp.dictionaries[locale] == 'undefined') {
lp.getDictionary(locale);
return;
}

var $toTranslate = $from ? $from.find('.translatable') : $('.translatable');
$toTranslate.each(function(idxe, element) {
var $element = $(element);
var translation = '';

if (typeof lp.dictionaries[locale][$element.data('translatable')] == 'string') {
translation = lp.dictionaries[locale][$element.data('translatable')];
} else {
translation = $element.data('translatable');
}
if ($element.html()) {
$element.html(translation);
}
// need i18n
// if ($element.data('text')) {
// $element.data('text', translation);
// }
} );
},

initTranslation: function($from) {
var $toInit = $from ? $from.find('.translatable') : $('.translatable');
$toInit.each(function(idxe, element) {
var $element = $(element);
$element.data('translatable', $element.html().replace(/"/g, '\''));
} );
},

} );

$(document).ready(function() {

// Create translations availables
var $locale = $('#locale');
$.each(lp.locales, function(lidx, locale) {
var $li = $('<li />');
var $a = $('<a href="#" id="lang-' + locale.id + '" />')
.html('<img src="images/countries/' + locale.id + '.png" alt="' + locale.name + ' flag" />')
.click(function() {
lp.setLocale(locale.id);
return false;
} )
.appendTo($li);
$li.appendTo($locale);
} );


lp.initTranslation();
lp.setLocale();

} );
41 changes: 41 additions & 0 deletions js/jquery.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {

// key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);

if (value === null || value === undefined) {
options.expires = -1;
}

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}

value = String(value);

return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
2 changes: 1 addition & 1 deletion js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ function loaded(view, doc) {
script.loaded(doc);
});
});
}
}
1 change: 1 addition & 0 deletions js/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
26 changes: 26 additions & 0 deletions js/locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Translation Test":
"Test de traduction",

"Libre Docs":
"Libre Docs",

"<a href='/'>Libre Docs</a> is a <a href='https://github.com/unhosted/libredocs'>free software</a> app by <a href='http://unhosted.org'>Unhosted</a> for a more open web.":
"<a href='/'>Libre Docs</a> est un <a href='https://github.com/unhosted/libredocs'>Logiciel Libre</a> développé par <a href='http://unhosted.org'>Unhosted</a> pour un web plus ouvert.",

"Liberate your ideas":
"Libérez vos idées",

"1. get remoteStorage":
"1. obtenir un stockage distant",

"2. connect":
"2. connectez-vous",

"3. write freely!":
"3. Écrivez librement!",

"+ New document":
"+ Nouveau document"

}
Loading