Added a "Language Settings" menu at index

Now the language manually set has priority over the browser lang
Update translations
This commit is contained in:
Blakko 2013-07-12 11:12:33 +02:00
parent 13722c467b
commit e6e6c8c002
11 changed files with 141 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.refine.ProjectManager;
import com.google.refine.commands.Command;
public class LoadLanguageCommand extends Command {
@ -33,9 +34,14 @@ public class LoadLanguageCommand extends Command {
.getRealPath("extensions/freebase/module/langs/");
String cleanedDirectory = rawDirectoryFile.replace("main" + File.separator + "webapp" + File.separator, "");
BufferedReader reader = null;
String[] langs = request.getParameterValues("lng");
langs = langs[0].split(" ");
BufferedReader reader = null;String param = null;
try {
param = (String) ProjectManager.singleton.getPreferenceStore().get("userLang");
} catch (NullPointerException e) {
}
if (param == null) param = request.getParameter("lng");
String[] langs = param.split(" ");
try {
String file = cleanedDirectory + File.separator + "translation-" + langs[0] + ".json";
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));

View File

@ -12,6 +12,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.refine.ProjectManager;
import com.google.refine.commands.Command;
public class LoadLanguageCommand extends Command {
@ -34,8 +35,14 @@ public class LoadLanguageCommand extends Command {
String cleanedDirectory = rawDirectoryFile.replace("main" + File.separator + "webapp" + File.separator, "");
BufferedReader reader = null;
String[] langs = request.getParameterValues("lng");
langs = langs[0].split(" ");
String param = null;
try {
param = (String) ProjectManager.singleton.getPreferenceStore().get("userLang");
} catch (NullPointerException e) {
}
if (param == null) param = request.getParameter("lng");
String[] langs = param.split(" ");
try {
String file = cleanedDirectory + File.separator + "translation-" + langs[0] + ".json";
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));

View File

@ -12,6 +12,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.refine.ProjectManager;
import com.google.refine.commands.Command;
public class LoadLanguageCommand extends Command {
@ -29,13 +30,19 @@ public class LoadLanguageCommand extends Command {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String rawDirectoryFile = request.getSession().getServletContext()
.getRealPath("webapp/modules/langs/");
String cleanedDirectory = rawDirectoryFile.replace("main" + File.separator + "webapp" + File.separator, "main" + File.separator);
String rawDirectoryFile = request.getSession().getServletContext().getRealPath("webapp/modules/langs/");
String cleanedDirectory = rawDirectoryFile.replace("main" + File.separator + "webapp" + File.separator, "main"
+ File.separator);
BufferedReader reader = null;
String[] langs = request.getParameterValues("lng");
langs = langs[0].split(" ");
String param = null;
try {
param = (String) ProjectManager.singleton.getPreferenceStore().get("userLang");
} catch (NullPointerException e) {
}
if (param == null) param = request.getParameter("lng");
String[] langs = param.split(" ");
try {
String file = cleanedDirectory + File.separator + "translation-" + langs[0] + ".json";
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
@ -63,5 +70,4 @@ public class LoadLanguageCommand extends Command {
response.getWriter().flush();
response.getWriter().close();
}
}

View File

@ -0,0 +1,33 @@
package com.google.refine.commands.lang;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.refine.ProjectManager;
import com.google.refine.commands.Command;
import com.google.refine.preference.PreferenceStore;
public class SetLanguageCommand extends Command {
public SetLanguageCommand() {
// TODO Auto-generated constructor stub
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String lang = request.getParameter("lng");
PreferenceStore pref = ProjectManager.singleton.getPreferenceStore();
pref.put("userLang", lang);
}
}

View File

@ -99,6 +99,7 @@ function registerCommands() {
RS.registerCommand(module, "key-value-columnize", new Packages.com.google.refine.commands.cell.KeyValueColumnizeCommand());
RS.registerCommand(module, "load-language", Packages.com.google.refine.commands.lang.LoadLanguageCommand());
RS.registerCommand(module, "set-language", Packages.com.google.refine.commands.lang.SetLanguageCommand());
RS.registerCommand(module, "add-column", new Packages.com.google.refine.commands.column.AddColumnCommand());
RS.registerCommand(module, "add-column-by-fetching-urls", new Packages.com.google.refine.commands.column.AddColumnByFetchingURLsCommand());
@ -331,6 +332,7 @@ function init() {
"scripts/index/create-project-ui.js",
"scripts/index/open-project-ui.js",
"scripts/index/import-project-ui.js",
"scripts/index/lang-settings-ui.js",
"scripts/index/default-importing-controller/controller.js",
"scripts/index/default-importing-controller/file-selection-panel.js",

View File

@ -0,0 +1,21 @@
<div class="grid-layout layout-normal" id="project-upload-form">
<table>
<tr>
<td colspan="2" bind="or_lang_label"></td>
</tr>
<tr></tr>
<tr>
<td></td>
<td><select id="langDD">
<option value="en" selected>English</option>
<option value="it">Italian</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="set-lang-button" bind="set_lan_btn"
class="button button-primary" /></td>
</tr>
</table>
</div>

View File

@ -0,0 +1,35 @@
Refine.SetLanguageUI = function(elmt) {
var self = this;
elmt.html(DOM.loadHTML("core", "scripts/index/lang-settings-ui.html"));
this._elmt = elmt;
this._elmts = DOM.bind(elmt);
this._elmts.or_lang_label.text($.i18n._('core-index-lang')["label"]+":");
this._elmts.set_lan_btn.attr("value", $.i18n._('core-index-lang')["send-req"]);
this._elmts.set_lan_btn.bind('click', function(e) {
$.ajax({
url : "/command/core/set-language?",
type : "POST",
async : false,
data : {
lng : $("#langDD option:selected").val()
},
success : function(data) {
alert($.i18n._('core-index-lang')["page-reload"]);
location.reload(true);
}
});
});
};
Refine.SetLanguageUI.prototype.resize = function() {
};
Refine.actionAreas.push({
id : "lang-settings",
label : $.i18n._('core-index-lang')["lang-settings"],
uiClass : Refine.SetLanguageUI
});

View File

@ -105,7 +105,7 @@ Refine.JsonParserUI.prototype._initialize = function() {
this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); });
this._optionContainerElmts.pickRecordElementsButton.text($.i18n._('core-index-import')["warning-record-path"]);
this._optionContainerElmts.previewButton.text($.i18n._('core-buttons')["update-preview"]);
this._optionContainerElmts.previewButton.html($.i18n._('core-buttons')["update-preview"]);
$('#or-import-load').text($.i18n._('core-index-parser')["load-at-most"]);
$('#or-import-rows').text($.i18n._('core-index-parser')["rows-data"]);
$('#or-import-preserve').text($.i18n._('core-index-parser')["preserve-empty"]);

View File

@ -95,6 +95,12 @@
"warning-data-file": "You must specify a data file to upload or a URL to retrieve.",
"browse": "Browse workspace directory"
},
"core-index-lang": {
"lang-settings": "Language Settings",
"label": "Select preferred language",
"send-req": "Send Request",
"page-reload": "Warning, the page will be refreshed to apply the change!"
},
"core-index-parser":{
"ignore-first": "Ignore first",
"lines-beg": "line(s) at beginning of file",

View File

@ -95,6 +95,12 @@
"warning-data-file": "You must specify a data file to upload or a URL to retrieve.",
"browse": "Browse workspace directory"
},
"core-index-lang": {
"lang-settings": "Language Settings",
"label": "Select preferred language",
"send-req": "Send Request",
"page-reload": "Warning, the page will be refreshed to apply the change!"
},
"core-index-parser":{
"ignore-first": "Ignore first",
"lines-beg": "line(s) at beginning of file",

View File

@ -95,6 +95,12 @@
"warning-data-file": "Devi specificare un file da caricare oppure una URL da cui recuperare dati.",
"browse": "Naviga la cartella del workspace"
},
"core-index-lang": {
"lang-settings": "Impostazioni Lingua",
"label": "Seleziona la lingua preferita",
"send-req": "Invia Richiesta",
"page-reload": "Attenzione, la pagina verrà ricaricata per applicare la modifica"
},
"core-index-parser":{
"ignore-first": "Ignora la/e prima/e",
"lines-beg": "linea/e all'inizio del file",