Revision: 6295
http://languagetool.svn.sourceforge.net/languagetool/?rev=6295&view=rev
Author: dnaber
Date: 2012-01-19 22:45:22 +0000 (Thu, 19 Jan 2012)
Log Message:
-----------
[web] enable auto-detection of language
Modified Paths:
--------------
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
trunk/ltcommunity/grails-app/i18n/messages.properties
trunk/ltcommunity/grails-app/views/homepage/checkText.gsp
trunk/ltcommunity/web-app/css/main.css
Modified:
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
===================================================================
---
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
2012-01-19 21:07:56 UTC (rev 6294)
+++
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
2012-01-19 22:45:22 UTC (rev 6295)
@@ -22,6 +22,7 @@
import org.hibernate.*
import org.languagetool.*
import org.languagetool.rules.*
+import org.apache.tika.language.LanguageIdentifier
/**
* The main page of the website.
@@ -88,7 +89,23 @@
*/
def checkText = {
String lang = "en"
- if (params.lang) lang = params.lang
+ boolean autoLangDetectionWarning = false
+ List languages = Language.REAL_LANGUAGES
+ languages.sort{it.getName()}
+ Language detectedLang
+ if (params.lang == "auto") {
+ LanguageIdentifier identifier = new LanguageIdentifier(params.text)
+ detectedLang =
Language.getLanguageForShortName(identifier.getLanguage())
+ if (detectedLang == null) {
+ throw new
Exception(message(code:'ltc.home.check.detection.failure',
args:[Arrays.asList(languages)]))
+ }
+ lang = detectedLang.getShortName()
+ params.lang = lang
+ // TODO: use identifier.isReasonablyCertain() - but make sure it
works!
+ autoLangDetectionWarning = params.text?.length() < 60
+ } else if (params.lang) {
+ lang = params.lang
+ }
JLanguageTool lt = new
JLanguageTool(Language.getLanguageForShortName(lang))
lt.activateDefaultPatternRules()
List userRules = getUserRules()
@@ -113,8 +130,9 @@
}
List ruleMatches = lt.check(text)
// TODO: count only disabledRules for the current language
- [matches: ruleMatches, lang: lang, textToCheck: params.text,
- disabledRules: langConfig?.disabledRules]
+ [matches: ruleMatches, lang: lang, languages: languages, textToCheck:
params.text,
+ disabledRules: langConfig?.disabledRules,
+ autoLangDetectionWarning: autoLangDetectionWarning, detectedLang:
detectedLang]
}
private getUserRules() {
Modified: trunk/ltcommunity/grails-app/i18n/messages.properties
===================================================================
--- trunk/ltcommunity/grails-app/i18n/messages.properties 2012-01-19
21:07:56 UTC (rev 6294)
+++ trunk/ltcommunity/grails-app/i18n/messages.properties 2012-01-19
22:45:22 UTC (rev 6295)
@@ -22,6 +22,8 @@
ltc.login.to.configure=Note that you can log in to activate and deactivate
only those rules that are important to you.
ltc.home.links=<strong>Visit <a href="http://www.languagetool.org">the
LanguageTool homepage</a> to download LanguageTool as an extension for <a
href="http://www.libreoffice.org">LibreOffice</a> or <a
href="http://www.openoffice.org">OpenOffice.org</a></strong><a
href="http://www.openoffice.org"></a>
ltc.check.visit.rule=[Visit Rule]
+ltc.home.check.detection.warning=Language detected as <strong>{0}</strong> -
the text you supplied was very short. If we mis-detect the language of your
text, please use a longer input text or set the text language manually
+ltc.home.check.detection.failure=Sorry, we could not detect the language of
your text. Please use more text and note that LanguageTool supports only the
following languages: {0}
ltc.login.title=LanguageTool Community Login
ltc.login.no.account=No Account yet?
Modified: trunk/ltcommunity/grails-app/views/homepage/checkText.gsp
===================================================================
--- trunk/ltcommunity/grails-app/views/homepage/checkText.gsp 2012-01-19
21:07:56 UTC (rev 6294)
+++ trunk/ltcommunity/grails-app/views/homepage/checkText.gsp 2012-01-19
22:45:22 UTC (rev 6295)
@@ -1,16 +1,16 @@
<%@page import="org.languagetool.*" %>
<%@page import="org.hibernate.*" %>
-<html>
- <head>
+<html>
+ <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <title><g:message code="ltc.home.check.title"/></title>
+ <title><g:message code="ltc.home.check.title"/></title>
<meta name="layout" content="main" />
- </head>
- <body>
+ </head>
+ <body>
<div class="body">
-
+
<h1><g:message code="ltc.home.check.title"/></h1>
<g:if test="${session.user}">
@@ -25,21 +25,23 @@
</g:if>
<br/>
+ <g:if test="${autoLangDetectionWarning}">
+ <div class="warn"><g:message
code="ltc.home.check.detection.warning" args="${[detectedLang]}"/></div>
+ </g:if>
+
<g:render template="/ruleMatches"/>
<br />
<p><g:message code="ltc.home.check.again"/></p>
<g:form method="post">
- <input type="hidden" name="lang"
value="${params.lang.encodeAsHTML()}"/>
-
<g:textArea name="text" value="${textToCheck}" rows="5"
cols="80" />
<br />
<g:actionSubmit action="checkText"
value="${message(code:'ltc.home.check.text')}"/>
-
+ Language: <g:select name="lang"
from="${languages}" optionKey="shortName"
noSelection="${['auto':'auto-detect']}" value="${params.lang}"></g:select>
</g:form>
</div>
-
- </body>
+
+ </body>
</html>
\ No newline at end of file
Modified: trunk/ltcommunity/web-app/css/main.css
===================================================================
--- trunk/ltcommunity/web-app/css/main.css 2012-01-19 21:07:56 UTC (rev
6294)
+++ trunk/ltcommunity/web-app/css/main.css 2012-01-19 22:45:22 UTC (rev
6295)
@@ -116,6 +116,14 @@
padding: 5px 5px 5px 30px
}
+.warn {
+ border: 1px solid #ae985d;
+ color: #524c2e;
+ background: #ffdf88;
+ margin: 10px 0 5px 0;
+ padding: 5px 5px 5px 30px
+}
+
div.errors {
background: #fff3f3;
border: 1px solid red;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs