[jsword-svn] r1324 - in trunk/bibledesktop/src/main: java/org/crosswire/bibledesktop/desktop resources
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Wed May 16 13:27:21 MST 2007
Author: dmsmith
Date: 2007-05-16 13:27:20 -0700 (Wed, 16 May 2007)
New Revision: 1324
Added:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java
Modified:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
trunk/bibledesktop/src/main/resources/config.properties
trunk/bibledesktop/src/main/resources/config.xml
Log:
Added the ability to select a translation in which to display BibleDesktop
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java 2007-05-16 14:08:12 UTC (rev 1323)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java 2007-05-16 20:27:20 UTC (rev 1324)
@@ -147,12 +147,12 @@
public Desktop()
{
// Allow the setting of user.language and user.country to influence the default locale
- String language = System.getProperty("user.language"); //$NON-NLS-1$
- String locale = null;
- if (language != null)
- {
- locale = language;
- }
+// String language = System.getProperty("user.language"); //$NON-NLS-1$
+// String locale = null;
+// if (language != null)
+// {
+// locale = language;
+// }
// LATER(DMS): support country based locales
// String country = System.getProperty("user.country"); //$NON-NLS-1$
@@ -165,10 +165,10 @@
// locale += country;
// }
- if (locale != null && !"en".equals(locale)) //$NON-NLS-1$
- {
- Locale.setDefault(new Locale(locale));
- }
+// if (locale != null && !"en".equals(locale)) //$NON-NLS-1$
+// {
+// Locale.setDefault(new Locale(locale));
+// }
// Load the configuration.
// This has to be done before any gui components are created.
@@ -176,6 +176,8 @@
// This includes code that is invoked by it.
generateConfig();
+ Locale.setDefault(Translations.getCurrentLocale());
+
// Make this be the root frame of optiondialogs
JOptionPane.setRootFrame(this);
@@ -989,6 +991,8 @@
{
refreshBooks();
+ Translations.register();
+
// And the array of allowed osis>html converters
Map converters = ConverterFactory.getKnownConverters();
Set keys = converters.keySet();
Added: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java (rev 0)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java 2007-05-16 20:27:20 UTC (rev 1324)
@@ -0,0 +1,129 @@
+/**
+ * Distribution License:
+ * BibleDesktop is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, version 2 as published by
+ * the Free Software Foundation. This program 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.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ * The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: ViewSourcePane.java 1312 2007-05-03 21:39:51Z dmsmith $
+ */
+package org.crosswire.bibledesktop.desktop;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.crosswire.common.config.ChoiceFactory;
+import org.crosswire.common.util.Languages;
+
+/**
+ * Translations provides a list of languages that BibleDesktop has been translated into.
+ *
+ * @see gnu.gpl.License for license details.
+ * The copyright to this program is held by it's authors.
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class Translations
+{
+ /**
+ * Utility classes have private constructors.
+ */
+ private Translations()
+ {
+ }
+
+ public static String[] getSupportedTranslations()
+ {
+ List names = new ArrayList();
+
+ for (int i = 0; i < translations.length; i++)
+ {
+ names.add(Languages.getLanguage(translations[i]));
+ }
+
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+
+ /**
+ * Get the locale for the current translation.
+ * @return the translation's locale
+ */
+ public static Locale getCurrentLocale()
+ {
+ return new Locale(translation);
+ }
+
+ /**
+ * Get the current translation as a human readable string.
+ *
+ * @return the current translation
+ */
+ public static String getCurrentTranslation()
+ {
+ return Languages.getLanguage(translation);
+ }
+
+ /**
+ * Set the current translation, using human readable string.
+ *
+ * @param translation the translation to use
+ */
+ public static void setCurrentTranslation(String translation)
+ {
+ String lang = DEFAULT_TRANSLATION;
+ String currentLang = ""; //$NON-NLS-1$
+ for (int i = 0; i < translations.length; i++)
+ {
+ currentLang = Languages.getLanguage(translations[i]);
+ if (currentLang.equals(translation))
+ {
+ lang = translations[i];
+ }
+ }
+
+ Translations.translation = lang;
+ }
+
+ public static void register()
+ {
+ ChoiceFactory.getDataMap().put(TRANSLATION_KEY, getSupportedTranslations());
+ }
+
+ /**
+ * The key used in config.xml
+ */
+ private static final String TRANSLATION_KEY = "translation-codes"; //$NON-NLS-1$
+
+ /**
+ * The default translation, if the user has not chosen anything else.
+ */
+ private static final String DEFAULT_TRANSLATION = "en"; //$NON-NLS-1$
+
+ /**
+ * The language that BibleDesktop should use.
+ */
+ private static String translation = DEFAULT_TRANSLATION;
+
+ /**
+ * List of available languages.
+ * TODO(DMS): externalize this list.
+ */
+ private static String[] translations = {
+ "en", //$NON-NLS-1$
+ "de", //$NON-NLS-1$
+ "fa", //$NON-NLS-1$
+ };
+
+}
Modified: trunk/bibledesktop/src/main/resources/config.properties
===================================================================
--- trunk/bibledesktop/src/main/resources/config.properties 2007-05-16 14:08:12 UTC (rev 1323)
+++ trunk/bibledesktop/src/main/resources/config.properties 2007-05-16 20:27:20 UTC (rev 1324)
@@ -58,6 +58,8 @@
Passages.BookCase.alternative.0=lower
Passages.BookCase.alternative.1=Sentence
Passages.BookCase.alternative.2=UPPER
+Application.Language.path=Application.Language
+Application.Language.help=The language of the application.
Application.LookAndFeel.path=Application.Look and Feel
Application.LookAndFeel.help=The look and feel of the application.
Application.InitialLayout.path=Application.Initial Layout
Modified: trunk/bibledesktop/src/main/resources/config.xml
===================================================================
--- trunk/bibledesktop/src/main/resources/config.xml 2007-05-16 14:08:12 UTC (rev 1323)
+++ trunk/bibledesktop/src/main/resources/config.xml 2007-05-16 20:27:20 UTC (rev 1324)
@@ -198,6 +198,11 @@
</option>
-->
+ <option key="Application.Language" type="string-options">
+ <introspect class="org.crosswire.bibledesktop.desktop.Translations" property="CurrentTranslation"/>
+ <map name="translation-codes"/>
+ </option>
+
<option key="Application.InitialLayout" type="int-options">
<introspect class="org.crosswire.common.swing.desktop.ViewManager" property="InitialLayoutType"/>
<alternative number="0"/>
More information about the jsword-svn
mailing list