Commit 2effdb19 authored by Xavier de Blas's avatar Xavier de Blas

Implemented language change

parent 21b35c43
......@@ -99,6 +99,7 @@ esac
AM_CONDITIONAL(OSTYPE_WINDOWS, test x$ostype = xWindows)
AM_CONDITIONAL(OSTYPE_OS_X, test x$ostype = xOS_X)
AM_CONDITIONAL(OSTYPE_LINUX, test x$ostype = xLinux)
AC_SUBST(GMCS_FLAGS, ["$GMCS_FLAGS"])
AC_MSG_RESULT($ostype)
......
This diff is collapsed.
......@@ -35,7 +35,6 @@ SOURCES = \
gui/dialogMessage.cs\
gui/dialogCalendar.cs\
gui/dialogImageTest.cs\
gui/language.cs\
gui/repetitiveConditions.cs\
gui/convertWeight.cs\
gui/genericWindow.cs\
......@@ -155,6 +154,7 @@ SOURCES = \
utilDate.cs\
utilEncoder.cs\
utilGtk.cs\
utilLanguage.cs\
utilVideo.cs\
constants.cs\
report.cs\
......
......@@ -146,20 +146,31 @@ public class ChronoJump
Environment.Exit(1);
}
//string language = "es_ES"; //works
//string language = "es"; //works
string language = "cs";
Environment.SetEnvironmentVariable ("LANGUAGE", language); //works
string language = "";
if(File.Exists(System.IO.Path.Combine(Util.GetDatabaseDir(), "chronojump.db"))) {
try {
Sqlite.Connect();
language = SqlitePreferences.Select("language", false);
Sqlite.DisConnect();
if(language != "") {
Environment.SetEnvironmentVariable ("LANGUAGE", language); //works
#if OSTYPE_WINDOWS
g_setenv ("LANGUAGE", language, true);
g_setenv ("LANGUAGE", language, true);
#endif
}
}
catch {
LogB.Warning("Problem reading language on start");
}
}
Catalog.Init("chronojump",System.IO.Path.Combine(Util.GetPrefixDir(),"share/locale"));
Catalog.Init("chronojump",System.IO.Path.Combine(Util.GetPrefixDir(),"share/locale"));
new ChronoJump(args);
}
new ChronoJump(args);
}
bool createdSplashWin = false;
public static string RelativeToPrefix(string relativePath) {
......
......@@ -452,32 +452,7 @@ public class Constants
"LightGray", "LightGreen", "LightPink", "LightSalmon", "LightYellow",
"MediumBlue", "MediumOrchid", "MediumPurple", "MediumTurquoise", "MediumVioletRed", "YellowGreen"
};
//for windows, on linux it takes language ok from the locale
public static string LanguageDefault = "en-GB:English (United Kingdom)";
public static string [] Languages = {
"ca-ES:Catalan",
"zh-CN:Chinese",
LanguageDefault,
"dz-BT:Dzongkha",
"fi-FI:Finnish",
"fr-FR:French",
"oc-OC:Occitan",
"pt-BR:Portuguese (Brazil)",
"pt-PT:Portuguese (Portugal)",
"es-ES:Spanish (Spain)",
"sv-SE:Swedish",
"vi-VN:Vietnamese",
};
/* *** ATTENTIOn ***: dz-BT deactivated on Windows compilation...
* in the next release, do it better
*/
//TODO: add:
//ar (when there ara not fuzzy lines)
//see in both langs how to write as xx_XX
public static string PortNamesWindows =
string.Format(Catalog.GetString("Typical serial and USB-serial ports on Windows:") +
......
......@@ -404,9 +404,7 @@ public partial class ChronoJumpWindow
//windows needed
PreferencesWindow preferencesWin;
//LanguageWindow languageWin;
SessionAddEditWindow sessionAddEditWin;
//SessionEditWindow sessionEditWin;
SessionLoadWindow sessionLoadWin;
PersonRecuperateWindow personRecuperateWin;
PersonsRecuperateFromOtherSessionWindow personsRecuperateFromOtherSessionWin;
......
/*
* This file is part of ChronoJump
*
* ChronoJump is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ChronoJump 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2004-2015 Xavier de Blas <xaviblas@gmail.com>
*/
using System;
using Gtk;
using Glade;
using Mono.Unix;
public class LanguageWindow
{
[Widget] Gtk.Window language_window;
[Widget] Gtk.Button button_accept;
[Widget] Gtk.Box hbox_combo_language;
[Widget] Gtk.ComboBox combo_language;
[Widget] Gtk.Label label_linux_restart;
static LanguageWindow LanguageWindowBox;
public LanguageWindow ()
{
Glade.XML gladeXML;
gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", "language_window", "chronojump");
gladeXML.Autoconnect(this);
//put an icon to window
UtilGtk.IconWindow(language_window);
}
static public LanguageWindow Show ()
{
if (LanguageWindowBox == null) {
LanguageWindowBox = new LanguageWindow();
}
LanguageWindowBox.createComboLanguage();
/*
if(! UtilAll.IsWindows())
LanguageWindowBox.label_linux_restart.Text =
Catalog.GetString("On GNU/Linux you will need to restart Chronojump");
*/
LanguageWindowBox.language_window.Show ();
return LanguageWindowBox;
}
//private void createComboLanguage(string myLanguage) {
private void createComboLanguage() {
combo_language = ComboBox.NewText ();
UtilGtk.ComboUpdate(combo_language, Util.GetLanguagesNames(), "");
hbox_combo_language.PackStart(combo_language, false, false, 0);
hbox_combo_language.ShowAll();
combo_language.Active = UtilGtk.ComboMakeActive(Util.GetLanguagesNames(), Util.GetLanguageName(Constants.LanguageDefault));
//if(UtilAll.IsWindows())
combo_language.Sensitive = true;
//else
// combo_language.Sensitive = false;
}
//void on_language_destroy (object o, EventArgs args)
void on_delete_event (object o, DeleteEventArgs args)
{
/*
* do nothing, cannot be deleted because:
* - windows decorations are not shown
* - and is not shown on taskBar and Paginator
*
* LanguageWindowBox.language_window.Hide();
* LanguageWindowBox = null;
*/
}
protected void on_button_accept_clicked (object o, EventArgs args)
{
SqlitePreferences.Update("language", Util.GetLanguageCodeFromName(UtilGtk.ComboGetActive(LanguageWindowBox.combo_language)), false);
LanguageWindowBox.language_window.Hide();
LanguageWindowBox = null;
}
public Button ButtonAccept
{
get {
return button_accept;
}
}
~LanguageWindow() {}
}
......@@ -29,6 +29,8 @@ using System.Text; //StringBuilder
using System.Collections; //ArrayList
using Mono.Unix;
using System.Threading;
using System.Globalization; //CultureInfo stuff
public class PreferencesWindow {
......@@ -109,11 +111,10 @@ public class PreferencesWindow {
[Widget] Gtk.RadioButton radio_graphs_no_translate;
// [Widget] Gtk.Box hbox_language_row;
// [Widget] Gtk.Box hbox_combo_language;
// [Widget] Gtk.ComboBox combo_language;
[Widget] Gtk.Box hbox_combo_language;
[Widget] Gtk.ComboBox combo_language;
[Widget] Gtk.RadioButton radio_language_detected;
[Widget] Gtk.RadioButton radio_language_force;
[Widget] Gtk.Button button_accept;
......@@ -125,12 +126,10 @@ public class PreferencesWindow {
private Preferences preferences; //stored to update SQL if anything changed
private Thread thread;
//language when window is called. If changes, then change data in sql and show
//dialogMessage
//private string languageIni;
string databaseURL;
string databaseTempURL;
ListStore langsStore;
PreferencesWindow () {
......@@ -156,13 +155,9 @@ public class PreferencesWindow {
PreferencesWindowBox.preferences = preferences;
//PreferencesWindowBox.languageIni = language;
//if(UtilAll.IsWindows())
// PreferencesWindowBox.createComboLanguage(language);
//else
PreferencesWindowBox.hideLanguageStuff();
PreferencesWindowBox.createComboLanguage();
PreferencesWindowBox.createComboCamera(UtilVideo.GetVideoDevices(), preferences.videoDeviceNum);
PreferencesWindowBox.createComboCamera(UtilVideo.GetVideoDevices(), preferences.videoDeviceNum);
string [] decs = {"1", "2", "3"};
PreferencesWindowBox.combo_decimals.Active = UtilGtk.ComboMakeActive(
......@@ -285,7 +280,12 @@ public class PreferencesWindow {
//done here and not in glade to be shown with the decimal point of user language
PreferencesWindowBox.label_encoder_con.Text = (0.7).ToString();
if(preferences.language == "")
PreferencesWindowBox.radio_language_detected.Active = true;
else
PreferencesWindowBox.radio_language_force.Active = true;
if(preferences.RGraphsTranslate)
PreferencesWindowBox.radio_graphs_translate.Active = true;
else
......@@ -322,39 +322,56 @@ public class PreferencesWindow {
combo_camera.Active = UtilGtk.ComboMakeActive(devices, devices[current]);
}
private void createComboLanguage(string myLanguageCode) {
/*
combo_language = ComboBox.NewText ();
UtilGtk.ComboUpdate(combo_language, Util.GetLanguagesNames(), "");
// ---- Language stuff
//private void createComboLanguage(string myLanguageCode) {
private void createComboLanguage() {
//combo_language.Entry.Changed += new EventHandler (on_combo_language_changed);
combo_language = ComboBox.NewText ();
fillLanguages();
hbox_combo_language.PackStart(combo_language, false, false, 0);
hbox_combo_language.ShowAll();
bool found = false;
int count = 0;
foreach (string lang in Constants.Languages) {
if (myLanguageCode == Util.GetLanguageCode(lang)) {
combo_language.Active = count;
found = true;
}
count ++;
}
//from Longomatch ;)
//(C) Andoni Morales Alastruey
void fillLanguages () {
int index = 0, active = 0;
langsStore = new ListStore(typeof(string), typeof(CultureInfo));
foreach (CultureInfo lang in UtilLanguage.Languages) {
langsStore.AppendValues(lang.DisplayName, lang);
if (preferences.language != "" && lang.Name == preferences.language)
active = index;
index ++;
}
if(!found)
combo_language.Active = UtilGtk.ComboMakeActive(Constants.Languages, Util.GetLanguageName(Constants.LanguageDefault));
//if(UtilAll.IsWindows())
// combo_language.Sensitive = true;
//else
combo_language.Sensitive = false;
*/
combo_language.Model = langsStore;
combo_language.Active = active;
}
private void hideLanguageStuff() {
//hbox_language_row.Hide();
private void on_radio_language_toggled (object obj, EventArgs args) {
hbox_combo_language.Sensitive = radio_language_force.Active;
}
string getSelectedLanguage()
{
TreeIter iter;
CultureInfo info;
combo_language.GetActiveIter (out iter);
info = (CultureInfo) langsStore.GetValue (iter, 1);
if (info == null) {
return "";
} else {
return info.Name;
}
}
// ---- end of Language stuff
private void on_checkbutton_show_tv_tc_index_clicked (object o, EventArgs args) {
if(checkbutton_show_tv_tc_index.Active)
hbox_indexes.Show();
......@@ -802,6 +819,19 @@ public class PreferencesWindow {
preferences.CSVExportDecimalSeparator = "POINT";
}
string selectedLanguage = getSelectedLanguage();
//if there was a language on SQL but now "detected" is selected, put "" in language on SQL
if(preferences.language != "" && radio_language_detected.Active) {
SqlitePreferences.Update("language", "", true);
preferences.language = "";
}
//if force a language, and SQL language is != than selected language, change language on SQL
else if(radio_language_force.Active && preferences.language != selectedLanguage) {
SqlitePreferences.Update("language", selectedLanguage, true);
preferences.language = selectedLanguage;
}
if( preferences.RGraphsTranslate != PreferencesWindowBox.radio_graphs_translate.Active ) {
SqlitePreferences.Update("RGraphsTranslate",
......@@ -843,24 +873,6 @@ public class PreferencesWindow {
Sqlite.Close();
/*
if(UtilAll.IsWindows()) {
//if language has changed
if(UtilGtk.ComboGetActive(PreferencesWindowBox.combo_language) != languageIni) {
string myLanguage = SqlitePreferences.Select("language");
if ( myLanguage != null && myLanguage != "" && myLanguage != "0") {
//if language exists in sqlite preferences update it
SqlitePreferences.Update("language", Util.GetLanguageCodeFromName(UtilGtk.ComboGetActive(PreferencesWindowBox.combo_language)));
} else {
//else: create it
SqlitePreferences.Insert("language", Util.GetLanguageCodeFromName(UtilGtk.ComboGetActive(PreferencesWindowBox.combo_language)));
}
new DialogMessage(Catalog.GetString("Restart Chronojump to operate completely on your language."), true);
}
}
*/
PreferencesWindowBox.preferences_win.Hide();
PreferencesWindowBox = null;
}
......
......@@ -50,6 +50,7 @@ public class Preferences
public int videoDeviceNum; //AKA videoDevice
public Constants.Encoder1RMMethod encoder1RMMethod;
public string CSVExportDecimalSeparator;
public string language;
public bool RGraphsTranslate;
public bool useHeightsOnJumpIndexes;
public Constants.EncoderAutoSaveCurve encoderAutoSaveCurve;
......@@ -73,7 +74,6 @@ public class Preferences
//public string chronopicPort;
//public bool simulated;
//public string language;
//public double encoderSmoothEccCon; //unused
//public double inertialmomentum; //unused
......
......@@ -76,7 +76,7 @@ class Sqlite
/*
* Important, change this if there's any update to database
*/
static string lastChronojumpDatabaseVersion = "1.24";
static string lastChronojumpDatabaseVersion = "1.25";
public Sqlite() {
}
......@@ -1826,6 +1826,14 @@ class Sqlite
SqlitePreferences.Update ("databaseVersion", newVersion, true);
currentVersion = newVersion;
}
if(currentVersion == "1.24") {
LogB.SQL("Language defaults to (empty string), means detected");
SqlitePreferences.Update("language", "", true);
newVersion = "1.25";
SqlitePreferences.Update ("databaseVersion", newVersion, true);
currentVersion = newVersion;
}
// --- add more updates here
......@@ -1980,6 +1988,7 @@ class Sqlite
SqliteExecuteAuto.addChronojumpProfileAndBilateral();
//changes [from - to - desc]
//1.24 - 1.25 Converted DB to 1.25 Language defaults to (empty string), means detected
//1.23 - 1.24 Converted DB to 1.24 Delete runISpeedStartArrival and add 4 double contacts configs
//1.22 - 1.23 Converted DB to 1.23 Added encoder configuration
//1.21 - 1.22 Converted DB to 1.22 Encoder laterality in english again
......
......@@ -62,7 +62,7 @@ class SqlitePreferences : Sqlite
Insert ("askDeletion", "True", dbcmdTr);
Insert ("heightPreferred", "False", dbcmdTr);
Insert ("metersSecondsPreferred", "True", dbcmdTr);
Insert ("language", "es-ES", dbcmdTr);
Insert ("language", "", dbcmdTr);
Insert ("allowFinishRjAfterTime", "True", dbcmdTr);
Insert ("volumeOn", "True", dbcmdTr);
Insert ("videoOn", "True", dbcmdTr);
......@@ -216,6 +216,8 @@ class SqlitePreferences : Sqlite
preferences.videoDeviceNum = Convert.ToInt32(reader[1].ToString());
else if(reader[0].ToString() == "CSVExportDecimalSeparator")
preferences.CSVExportDecimalSeparator = reader[1].ToString();
else if(reader[0].ToString() == "language")
preferences.language = reader[1].ToString();
else if(reader[0].ToString() == "RGraphsTranslate")
preferences.RGraphsTranslate = reader[1].ToString() == "True";
else if(reader[0].ToString() == "useHeightsOnJumpIndexes")
......
......@@ -1214,54 +1214,6 @@ public class Util
}
}
/* LANGUAGES STUFF */
public static string GetLanguageCode(string languageString) {
string [] myStringFull = languageString.Split(new char[] {':'});
return myStringFull[0];
}
public static string GetLanguageName(string languageString) {
string [] myStringFull = languageString.Split(new char[] {':'});
return myStringFull[1];
}
public static string GetLanguageNameFromCode(string languageCode) {
foreach (string lang in Constants.Languages) {
if (languageCode == GetLanguageCode(lang)) {
return GetLanguageName(lang);
}
}
//if there's an error:
return GetLanguageName(Constants.LanguageDefault);
}
public static string GetLanguageCodeFromName(string languageName) {
foreach (string lang in Constants.Languages) {
if (languageName == GetLanguageName(lang)) {
return GetLanguageCode(lang);
}
}
//if there's an error:
return GetLanguageCode(Constants.LanguageDefault);
}
public static string [] GetLanguagesCodes() {
string [] codes = new string[Constants.Languages.Length];
int count = 0;
foreach (string lang in Constants.Languages)
codes[count++] = GetLanguageCode(lang);
return codes;
}
public static string [] GetLanguagesNames() {
string [] names = new string[Constants.Languages.Length];
int count = 0;
foreach (string lang in Constants.Languages)
names[count++] = GetLanguageName(lang);
return names;
}
public static string GetImagePath(bool mini) {
string returnString = "";
......
/*
* This file is part of ChronoJump
*
* ChronoJump is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ChronoJump 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2004-2015 Xavier de Blas <xaviblas@gmail.com>
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
public class UtilLanguage
{
//from Longomatch ;)
//(C) Andoni Morales Alastruey
public static List<CultureInfo> Languages {
get {
List<CultureInfo> langs;
string filename, localesDir;
langs = new List<CultureInfo>();
filename = String.Format ("{0}.mo", "chronojump");
localesDir = System.IO.Path.Combine(Util.GetPrefixDir(),"share/locale");
langs.Add (new CultureInfo ("en"));
if (!Directory.Exists (localesDir))
return langs;
foreach (string dirpath in Directory.EnumerateDirectories (localesDir)) {
if (File.Exists (Path.Combine (dirpath, "LC_MESSAGES", filename))) {
try {
string localeName = Path.GetFileName(dirpath).Replace("_", "-");
langs.Add(new CultureInfo (localeName));
} catch (Exception ex) {
LogB.Warning (ex.ToString());
}
}
}
return langs;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment