start i18n support

This commit is contained in:
Dietmar Maurer 2011-11-18 13:54:23 +01:00
parent 105270d30c
commit 2198a479fa
7 changed files with 55 additions and 18 deletions

View File

@ -3,7 +3,7 @@ include defines.mk
DESTDIR= DESTDIR=
#SUBDIRS = bin lib www aplinfo #SUBDIRS = bin lib www aplinfo
SUBDIRS = aplinfo PVE bin www SUBDIRS = aplinfo PVE bin www po
DEB=${PACKAGE}_${VERSION}-${PACKAGERELEASE}_all.deb DEB=${PACKAGE}_${VERSION}-${PACKAGERELEASE}_all.deb

View File

@ -182,7 +182,8 @@ Ext.define('PVE.Utils', { statics: {
language_map: { language_map: {
en: 'English', en: 'English',
de: 'German' de: 'German',
fr: 'French'
}, },
render_language: function (value) { render_language: function (value) {

View File

@ -25,10 +25,19 @@ sub send_output {
# NOTE: Requests to this page are not authenticated # NOTE: Requests to this page are not authenticated
# so we must be very careful here # so we must be very careful here
my $lang = 'en';
my $r = Apache2::RequestUtil->request(); my $r = Apache2::RequestUtil->request();
my $username; my $username;
my $token = 'null'; my $token = 'null';
if (my $cookie = $r->headers_in->{Cookie}) { if (my $cookie = $r->headers_in->{Cookie}) {
if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
if ($newlang =~ m/^[a-f]{2,3}(_A-F{2,3})?$/) {
$lang = $newlang;
}
}
my $ticket = PVE::REST::extract_auth_cookie($cookie); my $ticket = PVE::REST::extract_auth_cookie($cookie);
if (($username = PVE::AccessControl::verify_ticket($ticket, 1))) { if (($username = PVE::AccessControl::verify_ticket($ticket, 1))) {
$token = PVE::AccessControl::assemble_csrf_prevention_token($username); $token = PVE::AccessControl::assemble_csrf_prevention_token($username);
@ -48,6 +57,20 @@ if (!PVE) PVE = {};
PVE.GUIVersion = '$version'; PVE.GUIVersion = '$version';
PVE.UserName = '$username'; PVE.UserName = '$username';
PVE.CSRFPreventionToken = '$token'; PVE.CSRFPreventionToken = '$token';
_EOJS
my $langfile = "/usr/share/pve-manager/ext4/locale/ext-lang-${lang}.js";
$jssrc .= PVE::Tools::file_get_contents($langfile) if -f $langfile;
my $i18nsrc;
$langfile = "/usr/share/pve-manager/root/pve-lang-${lang}.js";
if (-f $langfile) {
$i18nsrc = PVE::Tools::file_get_contents($langfile);
} else {
$i18nsrc = 'function gettext(buf) { return buf; }';
}
$jssrc .= <<_EOJS;
Ext.require(['*', '$workspace']); Ext.require(['*', '$workspace']);
@ -60,8 +83,6 @@ Ext.onReady(function() { Ext.create('$workspace');});
_EOJS _EOJS
$jssrc .= "";
my $page = <<_EOD; my $page = <<_EOD;
<html> <html>
<head> <head>
@ -72,9 +93,9 @@ my $page = <<_EOD;
<link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" /> <link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="/pve2/css/ext-pve.css" /> <link rel="stylesheet" type="text/css" href="/pve2/css/ext-pve.css" />
<script type="text/javascript">$i18nsrc</script>
<script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script> <script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="/pve2/ext4/pvemanagerlib.js"></script> <script type="text/javascript" src="/pve2/ext4/pvemanagerlib.js"></script>
<script type="text/javascript">$jssrc</script> <script type="text/javascript">$jssrc</script>
</head> </head>

View File

@ -0,0 +1,4 @@
Ext.onReady(function() {
// fixme: how do we implement i18n?
//alert("LOADED LANG DE");
});

View File

@ -68,7 +68,7 @@ Ext.define('PVE.qemu.Config', {
}); });
var shutdownBtn = Ext.create('PVE.button.Button', { var shutdownBtn = Ext.create('PVE.button.Button', {
text: 'Shutdown', text: gettext('Shutdown'),
confirmMsg: "Do you really want to shutdown the VM?", confirmMsg: "Do you really want to shutdown the VM?",
handler: function() { handler: function() {
vm_command('shutdown', { timeout: 30 }); vm_command('shutdown', { timeout: 30 });

View File

@ -41,7 +41,7 @@ Ext.define('PVE.window.LoginWindow', {
closable: false, closable: false,
resizable: false, resizable: false,
layout: 'auto', layout: 'auto',
title: 'Proxmox VE Login', title: gettext('Proxmox VE Login'),
items: [{ items: [{
xtype: 'form', xtype: 'form',
@ -49,7 +49,6 @@ Ext.define('PVE.window.LoginWindow', {
url: '/api2/extjs/access/ticket', url: '/api2/extjs/access/ticket',
fieldDefaults: { fieldDefaults: {
labelWidth: 70,
labelAlign: 'right' labelAlign: 'right'
}, },
@ -61,9 +60,9 @@ Ext.define('PVE.window.LoginWindow', {
items: [ items: [
{ {
xtype: 'textfield', xtype: 'textfield',
fieldLabel: 'User name', fieldLabel: gettext('User name'),
name: 'username', name: 'username',
blankText: "Enter your user name", blankText: gettext("Enter your user name"),
listeners: { listeners: {
afterrender: function(f) { afterrender: function(f) {
// Note: only works if we pass delay 1000 // Note: only works if we pass delay 1000
@ -84,9 +83,9 @@ Ext.define('PVE.window.LoginWindow', {
{ {
xtype: 'textfield', xtype: 'textfield',
inputType: 'password', inputType: 'password',
fieldLabel: 'Password', fieldLabel: gettext('Password'),
name: 'password', name: 'password',
blankText: "Enter your password", blankText: gettext("Enter your password"),
listeners: { listeners: {
specialkey: function(field, e) { specialkey: function(field, e) {
if (e.getKey() === e.ENTER) { if (e.getKey() === e.ENTER) {
@ -98,11 +97,25 @@ Ext.define('PVE.window.LoginWindow', {
{ {
xtype: 'pveRealmComboBox', xtype: 'pveRealmComboBox',
name: 'realm' name: 'realm'
},
{
xtype: 'pveLanguageSelector',
fieldLabel: gettext('Language'),
value: Ext.util.Cookies.get('PVELangCookie') || 'en',
name: 'lang',
submitValue: false,
listeners: {
change: function(t, value) {
var dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
Ext.util.Cookies.set('PVELangCookie', value, dt);
window.location.reload();
}
}
} }
], ],
buttons: [ buttons: [
{ {
text: 'Login', text: gettext('Login'),
handler: function(){ handler: function(){
me.onLogon(); me.onLogon();
} }

View File

@ -57,21 +57,19 @@ my $ctime = scalar localtime;
my $header = << '.'; my $header = << '.';
# SOME DESCRIPTIVE TITLE. # SOME DESCRIPTIVE TITLE.
# Copyright (C) 2008 Proxmox Server Solutions GmbH # Copyright (C) 2011 Proxmox Server Solutions GmbH
# This file is distributed under the same license as the pve-manager package. # This file is distributed under the same license as the pve-manager package.
# Proxmox Support Team <support@proxmox.com>, 2008. # Proxmox Support Team <support@proxmox.com>, 2011.
# #
#, fuzzy
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: pve-manager 2\n"
. .
$header .= "\"Report-Msgid-Bugs-To: $opts{'msgid-bugs-address'}\\n\"\n" if $opts{'msgid-bugs-address'}; $header .= "\"Report-Msgid-Bugs-To: $opts{'msgid-bugs-address'}\\n\"\n" if $opts{'msgid-bugs-address'};
$header .= "\"POT-Creation-Date: $ctime\\n\"\n"; $header .= "\"POT-Creation-Date: $ctime\\n\"\n";
$header .= << '.'; $header .= << '.';
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <support@proxmox.com>\n" "Language-Team: LANGUAGE <support@proxmox.com>\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"