Bug 394347 - Lokalize uses wrong language for spell checking
Summary: Lokalize uses wrong language for spell checking
Status: RESOLVED FIXED
Alias: None
Product: lokalize
Classification: Applications
Component: editor (show other bugs)
Version: 2.0
Platform: openSUSE Linux
: NOR wishlist
Target Milestone: ---
Assignee: Simon Depiets
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-16 20:23 UTC by Karl Ove Hufthammer
Modified: 2020-05-03 15:19 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Ove Hufthammer 2018-05-16 20:23:34 UTC
Lokalize seems to randomly *guess* the language to use for spell-checking strings, resulting in many words incorrectly being marked as misspelled.

What it *should* do: 1) Use the language set in the file header or, if this doesn’t exist, 2) use the language set in the project options.

Simple demonstration that Lokalize guesses the language:

Open any PO file containing translations. Hover over the translation pane. A tooltip with the language name and code will be displayed (example: ‘Danish (da_DK)’). This is the language that is used for spell checking. Right-click on a word that is marked as misspelled to confirm (this shows a list of translation suggestions in that language). Move to a different string and observe that the language detected is (sometimes) different.

This is especially a problem for languages that are similar (share many words), e.g. Norwegian Nynorsk, Norwegian Bokmål and Danish.
Comment 1 Adrián Chaves (Gallaecio) 2018-05-27 10:37:21 UTC
Please, check that on the system-level spellchecking settings you do not have the first option checked, which enables automatic language detection, and works awfully for Galician.

I experienced the issue you are describing and it turned out that was the cause, and not Lokalize.
Comment 2 Karl Ove Hufthammer 2018-05-27 10:58:21 UTC
(In reply to Adrián Chaves (Gallaecio) from comment #1)
> Please, check that on the system-level spellchecking settings you do not
> have the first option checked, which enables automatic language detection,
> and works awfully for Galician.

Thanks, Adrián. That did the trick!

But I still think this is a bug though. Automatic language detection is useful for applications where the files don’t have language information (e.g. for Kate). But for applications like Lokalize, there should be a way to override to automatic language detection.
Comment 3 Simon Depiets 2020-01-01 15:12:25 UTC
I've tried to fix it by forcing the language (my lokalize is switching between various french dictionnaries and it is annoying indeed because you add exceptions and they are forgotten) but this is defined globally by Sonnet and not overridable (located in a private instance of Speller and loaded from global Settings).

Sonnet/Highlighter.cpp line 339
https://api.kde.org/frameworks/sonnet/html/highlighter_8cpp_source.html
const bool autodetectLanguage = d->spellchecker->testAttribute(Speller::AutoDetectLanguage);

I've opened a ticket for Sonnet with a patch, feel free to support.
https://phabricator.kde.org/D20935
Comment 4 Albert Astals Cid 2020-05-03 15:19:43 UTC
Git commit 422fac8a6f927e1e8df291773b8eba934b00aa1d by Albert Astals Cid, on behalf of Simon Depiets.
Committed on 03/05/2020 at 15:17.
Pushed by aacid into branch 'master'.

Allow overriding to disable auto language detection

Summary:
Currently, if language detection is enabled at Sonnet-wide level level, there is no way to disable it in a specific context.

In Lokalize for instance, the language of the source and target strings are already known by the application.

In that context, the language detection feature creates a lot of uncertainty in terms of spellchecking, as it may change quickly from one language to another or from one dictionnary to another within the same language. A user should not have to disable Sonnet-wide language detection to work around this, as it can be very useful elsewhere.

https://bugs.kde.org/show_bug.cgi?id=394347

Reviewers: #frameworks, cullmann, mlaurent, mludwig

Subscribers: aacid, mludwig, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D26342

M  +25   -0    autotests/test_highlighter.cpp
M  +13   -1    src/core/backgroundchecker.cpp
M  +19   -0    src/core/backgroundchecker.h
M  +2    -0    src/core/backgroundchecker_p.h
M  +14   -1    src/ui/highlighter.cpp
M  +19   -0    src/ui/highlighter.h

https://commits.kde.org/sonnet/422fac8a6f927e1e8df291773b8eba934b00aa1d