Revision: 6313
http://languagetool.svn.sourceforge.net/languagetool/?rev=6313&view=rev
Author: dnaber
Date: 2012-01-22 22:11:39 +0000 (Sun, 22 Jan 2012)
Log Message:
-----------
show better error message if text was empty or its language could not be
detected
Modified Paths:
--------------
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
trunk/ltcommunity/grails-app/views/_ruleMatches.gsp
trunk/ltcommunity/grails-app/views/homepage/checkText.gsp
Modified:
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
===================================================================
---
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
2012-01-22 21:22:19 UTC (rev 6312)
+++
trunk/ltcommunity/grails-app/controllers/org/languagetool/HomepageController.groovy
2012-01-22 22:11:39 UTC (rev 6313)
@@ -92,13 +92,18 @@
boolean autoLangDetectionWarning = false
List languages = Language.REAL_LANGUAGES
languages.sort{it.getName()}
- Language detectedLang
+ Language detectedLang = null
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)]))
+ String detectedLangCode = identifier.getLanguage()
+ if (detectedLangCode != 'unknown') {
+ detectedLang =
Language.getLanguageForShortName(detectedLangCode)
}
+ if (detectedLang == null || params.text.trim().length() == 0) {
+ render(view:"checkText", model:[matches: [], lang: "auto",
disabledRules: null, languages: languages,
+ autoLangDetectionWarning: false,
autoLangDetectionFailure: true, detectedLang: null])
+ return
+ }
lang = detectedLang.getShortName()
params.lang = lang
// TODO: use identifier.isReasonablyCertain() - but make sure it
works!
@@ -130,7 +135,7 @@
}
List ruleMatches = lt.check(text)
// TODO: count only disabledRules for the current language
- [matches: ruleMatches, lang: lang, languages: languages, textToCheck:
params.text,
+ [matches: ruleMatches, lang: lang, languages: languages,
disabledRules: langConfig?.disabledRules,
autoLangDetectionWarning: autoLangDetectionWarning, detectedLang:
detectedLang]
}
Modified: trunk/ltcommunity/grails-app/views/_ruleMatches.gsp
===================================================================
--- trunk/ltcommunity/grails-app/views/_ruleMatches.gsp 2012-01-22 21:22:19 UTC
(rev 6312)
+++ trunk/ltcommunity/grails-app/views/_ruleMatches.gsp 2012-01-22 22:11:39 UTC
(rev 6313)
@@ -10,12 +10,12 @@
<br/>
<span class="exampleSentence">${
org.languagetool.gui.Tools.getContext(matchInfo.getFromPos(),
- matchInfo.getToPos(), textToCheck,
+ matchInfo.getToPos(), params.text,
100, "<span class='error'>", "</span>", true)}</span>
<br />
</li>
</g:each>
- <g:if test="${matches.size() == 0}">
+ <g:if test="${matches != null && matches.size() == 0 && params.lang !=
'auto'}">
<li><g:message code="ltc.no.rule.matches"
args="${[Language.getLanguageForShortName(params.lang)]}"/></li>
</g:if>
</ul>
Modified: trunk/ltcommunity/grails-app/views/homepage/checkText.gsp
===================================================================
--- trunk/ltcommunity/grails-app/views/homepage/checkText.gsp 2012-01-22
21:22:19 UTC (rev 6312)
+++ trunk/ltcommunity/grails-app/views/homepage/checkText.gsp 2012-01-22
22:11:39 UTC (rev 6313)
@@ -28,6 +28,9 @@
<g:if test="${autoLangDetectionWarning}">
<div class="warn"><g:message
code="ltc.home.check.detection.warning" args="${[detectedLang]}"/></div>
</g:if>
+ <g:if test="${autoLangDetectionFailure}">
+ <div class="warn"><g:message
code="ltc.home.check.detection.failure" args="${[languages]}"/></div>
+ </g:if>
<g:render template="/ruleMatches"/>
@@ -35,7 +38,7 @@
<p><g:message code="ltc.home.check.again"/></p>
<g:form method="post">
- <g:textArea name="text" value="${textToCheck}" rows="5"
cols="80" />
+ <g:textArea name="text" value="${params.text}" 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>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
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-dev2
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs