Revision: 8958
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=8958&view=rev
Author:   dnaber
Date:     2013-01-12 15:20:03 +0000 (Sat, 12 Jan 2013)
Log Message:
-----------
bugfix: Portuguese translation was not used because its bundle file is "pt_PT" 
but we were only looking for "pt"; small whitespace cleanups

Modified Paths:
--------------
    trunk/JLanguageTool/CHANGES.txt
    trunk/JLanguageTool/src/main/java/org/languagetool/JLanguageTool.java
    trunk/JLanguageTool/src/main/java/org/languagetool/Language.java

Modified: trunk/JLanguageTool/CHANGES.txt
===================================================================
--- trunk/JLanguageTool/CHANGES.txt     2013-01-12 15:14:36 UTC (rev 8957)
+++ trunk/JLanguageTool/CHANGES.txt     2013-01-12 15:20:03 UTC (rev 8958)
@@ -31,6 +31,8 @@
 
 
  -bugfix: suggestions for compounds parts were missing sometimes
+ 
+ -bugfix: Portuguese translation was not used
 
  -stand-alone GUI: the very first check for languages with a lot of rules
   (e.g. German, French) should now be faster

Modified: trunk/JLanguageTool/src/main/java/org/languagetool/JLanguageTool.java
===================================================================
--- trunk/JLanguageTool/src/main/java/org/languagetool/JLanguageTool.java       
2013-01-12 15:14:36 UTC (rev 8957)
+++ trunk/JLanguageTool/src/main/java/org/languagetool/JLanguageTool.java       
2013-01-12 15:20:03 UTC (rev 8958)
@@ -171,10 +171,8 @@
    * Create a JLanguageTool and setup the built-in rules appropriate for the
    * given language.
    * 
-   * @param language
-   *          the language to be used.
-   * @param motherTongue
-   *          the user's mother tongue or <code>null</code>. The mother tongue
+   * @param language the language to be used.
+   * @param motherTongue the user's mother tongue or <code>null</code>. The 
mother tongue
    *          may also be used as a source language for checking bilingual 
texts.
    *          
    * @throws IOException
@@ -202,8 +200,7 @@
   /**
    * The grammar checker needs resources from following
    * directories:
-   * 
-   * <ul style="list-type: circle">
+   * <ul>
    * <li>{@code /resource}</li>
    * <li>{@code /rules}</li>
    * </ul>
@@ -217,17 +214,17 @@
    * @since 1.0.1
    */
   public static synchronized ResourceDataBroker getDataBroker() {
-         if (JLanguageTool.dataBroker == null) {
-                 JLanguageTool.dataBroker = new DefaultResourceDataBroker();
-         }
-         return JLanguageTool.dataBroker;
+    if (JLanguageTool.dataBroker == null) {
+      JLanguageTool.dataBroker = new DefaultResourceDataBroker();
+    }
+    return JLanguageTool.dataBroker;
   }
   
   /**
    * The grammar checker needs resources from following
    * directories:
    * 
-   * <ul style="list-type: circle">
+   * <ul>
    * <li>{@code /resource}</li>
    * <li>{@code /rules}</li>
    * </ul>
@@ -238,7 +235,7 @@
    * @since 1.0.1
    */
   public static synchronized void setDataBroker(ResourceDataBroker broker) {
-         JLanguageTool.dataBroker = broker;
+    JLanguageTool.dataBroker = broker;
   }
 
   /**
@@ -270,8 +267,18 @@
    */
   private static ResourceBundle getMessageBundle(final Language lang) {
     try {
-      final ResourceBundle bundle = 
ResourceBundle.getBundle("org.languagetool.MessagesBundle", 
-              lang.getLocale());
+      ResourceBundle bundle = 
ResourceBundle.getBundle("org.languagetool.MessagesBundle", 
lang.getLocaleWithCountry());
+      if (!isValidBundleFor(lang, bundle)) {
+        bundle = ResourceBundle.getBundle("org.languagetool.MessagesBundle", 
lang.getLocale());
+        if (!isValidBundleFor(lang, bundle)) {
+          // happens if 'xx' is requested but only a 
MessagesBundle_xx_YY.properties exists:
+          final Language defaultVariant = lang.getDefaultVariant();
+          if (defaultVariant != null && 
defaultVariant.getCountryVariants().length > 0) {
+            final Locale locale = new Locale(defaultVariant.getShortName(), 
defaultVariant.getCountryVariants()[0]);
+            bundle = 
ResourceBundle.getBundle("org.languagetool.MessagesBundle", locale);
+          }
+        }
+      }
       final ResourceBundle fallbackBundle = ResourceBundle.getBundle(
           "org.languagetool.MessagesBundle", Locale.ENGLISH);
       return new ResourceBundleWithFallback(bundle, fallbackBundle);
@@ -281,6 +288,10 @@
     }
   }
 
+  private static boolean isValidBundleFor(final Language lang, final 
ResourceBundle bundle) {
+    return 
lang.getLocale().getLanguage().equals(bundle.getLocale().getLanguage());
+  }
+
   private Rule[] getAllBuiltinRules(final Language language, final 
ResourceBundle messages) {
     final List<Rule> rules = new ArrayList<Rule>();
     final List<Class<? extends Rule>> languageRules = 
language.getRelevantRules();
@@ -854,7 +865,7 @@
     for (final Rule rule : rules) {
       rule.reset();
       if (!disabledRules.contains(rule.getId())) {
-         rulesActive.add(rule);
+        rulesActive.add(rule);
       }
     }    
     return rulesActive;
@@ -879,18 +890,18 @@
    * @param f - the file to be added.
    */
   public static void addTemporaryFile(final File f) {
-         temporaryFiles.add(f);
+    temporaryFiles.add(f);
   }
   
   /**
    * Clean up all temporary files, if there are any.
    */
   public static void removeTemporaryFiles() {
-         if (!temporaryFiles.isEmpty()) {
-                 for (File f : temporaryFiles) {
-                         f.delete();
-                 }
-         }
+    if (!temporaryFiles.isEmpty()) {
+      for (File f : temporaryFiles) {
+        f.delete();
+      }
+    }
   }
 
 }

Modified: trunk/JLanguageTool/src/main/java/org/languagetool/Language.java
===================================================================
--- trunk/JLanguageTool/src/main/java/org/languagetool/Language.java    
2013-01-12 15:14:36 UTC (rev 8957)
+++ trunk/JLanguageTool/src/main/java/org/languagetool/Language.java    
2013-01-12 15:20:03 UTC (rev 8958)
@@ -208,13 +208,25 @@
   // -------------------------------------------------------------------------
 
   /**
-   * Get this language's Java locale.
+   * Get this language's Java locale, not considering the country code.
    */
   public Locale getLocale() {
     return new Locale(getShortName());
   }
 
   /**
+   * Get this language's Java locale, considering language code and country 
code (if any).
+   * @since 2.1
+   */
+  public Locale getLocaleWithCountry() {
+    if (getCountryVariants().length > 0) {
+      return new Locale(getShortName(), getCountryVariants()[0]);
+    } else {
+      return getLocale();
+    }
+  }
+
+  /**
    * Get the location of the rule file(s).
    */
   public List<String> getRuleFileName() {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits

Reply via email to