diff options
author | Ingo Bauersachs <ingo@jitsi.org> | 2013-11-17 22:28:47 +0100 |
---|---|---|
committer | Ingo Bauersachs <ingo@jitsi.org> | 2013-11-18 20:50:22 +0100 |
commit | f5f23bb0ab2db88b45db84aef36588b3c234fbca (patch) | |
tree | 3f31a86c0fd5608cb83def5ce3792acbe8d70615 /src/net/java/sip/communicator/plugin/spellcheck | |
parent | ad504c01f6e07c3a7b80336c54934692c15826e1 (diff) | |
download | jitsi-f5f23bb0ab2db88b45db84aef36588b3c234fbca.zip jitsi-f5f23bb0ab2db88b45db84aef36588b3c234fbca.tar.gz jitsi-f5f23bb0ab2db88b45db84aef36588b3c234fbca.tar.bz2 |
Use system hunspell dictionary if it exists for the selected lang
Diffstat (limited to 'src/net/java/sip/communicator/plugin/spellcheck')
3 files changed, 51 insertions, 5 deletions
diff --git a/src/net/java/sip/communicator/plugin/spellcheck/Parameters.java b/src/net/java/sip/communicator/plugin/spellcheck/Parameters.java index 0b376f1..297d5d1 100644 --- a/src/net/java/sip/communicator/plugin/spellcheck/Parameters.java +++ b/src/net/java/sip/communicator/plugin/spellcheck/Parameters.java @@ -237,6 +237,19 @@ class Parameters } /** + * Gets the ICU locale, which is a combination of the ISO code and the + * country variant. English for the United States is therefore en_US, + * German for Switzerland de_CH. + * + * @return ICU locale + */ + public String getIcuLocale() + { + String[] parts = this.isoCode.split(","); + return parts[0].toLowerCase() + "_" + parts[1].toUpperCase(); + } + + /** * Provides the url where the dictionary resource can be found for this * language. * diff --git a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java index 1320485..f823775 100644 --- a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java +++ b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java @@ -17,6 +17,7 @@ import net.java.sip.communicator.util.*; import org.dts.spell.dictionary.*; import org.jitsi.service.fileaccess.*; +import org.jitsi.util.OSUtils; import org.osgi.framework.*; import javax.swing.*; @@ -51,6 +52,12 @@ class SpellChecker // filename of custom dictionary (added words) private static final String PERSONAL_DICT_NAME = "custom.per"; + /** + * System directory for hunspell-dictionaries. + */ + private static final String SYSTEM_HUNSPELL_DIR + = "net.java.sip.communicator.plugin.spellcheck.SYSTEM_HUNSPELL_DIR"; + /*- * Dictionary resources. * Note: Dictionary needs to be created with input streams that AREN'T CLOSED @@ -350,11 +357,27 @@ class SpellChecker File dictLocation = getLocalDictForLocale(locale); InputStream dictInput = null; + InputStream affInput = null; + + if (OSUtils.IS_LINUX && !dictLocation.exists()) + { + String sysDir = + SpellCheckActivator.getConfigService().getString( + SYSTEM_HUNSPELL_DIR); + File systemDict = + new File(sysDir, locale.getIcuLocale() + ".dic"); + if (systemDict.exists()) + { + dictInput = new FileInputStream(systemDict); + affInput = new FileInputStream(new File(sysDir, + locale.getIcuLocale() + ".aff")); + } + } - // downloads dictionary if unavailable (not cached) - if (!dictLocation.exists()) + if (!dictLocation.exists() && dictInput == null) { boolean dictFound = false; + // see if the requested locale is a built-in that doesn't // need to be downloaded @SuppressWarnings ("unchecked") @@ -379,13 +402,13 @@ class SpellChecker } } + // downloads dictionary if unavailable (not cached) if (!dictFound) { copyDictionary(locale.getDictUrl().openStream(), dictLocation); } } - if (dictInput == null) { @@ -395,9 +418,18 @@ class SpellChecker // resets dictionary being used to include changes synchronized (this.attachedChats) { - SpellDictionary dict = - new OpenOfficeSpellDictionary(dictInput, + SpellDictionary dict; + if (affInput == null) + { + dict = new OpenOfficeSpellDictionary(dictInput, this.personalDictLocation); + } + else + { + dict = + new OpenOfficeSpellDictionary(affInput, dictInput, + personalDictLocation, true); + } this.dict = dict; this.dictLocation = dictLocation; diff --git a/src/net/java/sip/communicator/plugin/spellcheck/spellCheck.manifest.mf b/src/net/java/sip/communicator/plugin/spellcheck/spellCheck.manifest.mf index 5ef7fdc..f03e786 100644 --- a/src/net/java/sip/communicator/plugin/spellcheck/spellCheck.manifest.mf +++ b/src/net/java/sip/communicator/plugin/spellcheck/spellCheck.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: jitsi.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + org.jitsi.util, org.jitsi.service.configuration, org.jitsi.service.fileaccess, net.java.sip.communicator.service.gui, |