Use system hunspell dictionary if it exists for the selected lang

cusax-fix
Ingo Bauersachs 12 years ago
parent ad504c01f6
commit f5f23bb0ab

@ -31,4 +31,7 @@ net.java.sip.communicator.service.protocol.jabber.AUTO_DISCOVER_JINGLE_NODES=tru
net.java.sip.communicator.service.protocol.jabber.ALLOW_NON_SECURE=false
net.java.sip.communicator.service.protocol.jabber.GMAIL_NOTIFICATIONS_ENABLED=false
net.java.sip.communicator.service.protocol.jabber.BYPASS_GTALK_CAPABILITIES=false
net.java.sip.communicator.service.protocol.jabber.GOOGLE_CONTACTS_ENABLED=true
net.java.sip.communicator.service.protocol.jabber.GOOGLE_CONTACTS_ENABLED=true
#Spellchecker config
net.java.sip.communicator.plugin.spellcheck.SYSTEM_HUNSPELL_DIR=/usr/share/hunspell

@ -236,6 +236,19 @@ public String getIsoCode()
return this.isoCode;
}
/**
* 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.

@ -17,6 +17,7 @@
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 @@ void setLocale(Parameters.Locale locale) throws Exception
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 @@ void setLocale(Parameters.Locale locale) throws Exception
}
}
// downloads dictionary if unavailable (not cached)
if (!dictFound)
{
copyDictionary(locale.getDictUrl().openStream(),
dictLocation);
}
}
if (dictInput == null)
{
@ -395,9 +418,18 @@ void setLocale(Parameters.Locale locale) throws Exception
// 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;

@ -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,

Loading…
Cancel
Save