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.
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.
(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.
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
const bool autodetectLanguage = d->spellchecker->testAttribute(Speller::AutoDetectLanguage);
I've opened a ticket for Sonnet with a patch, feel free to support.
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
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.
Reviewers: #frameworks, cullmann, mlaurent, mludwig
Subscribers: aacid, mludwig, kde-frameworks-devel
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