Commit graph

188 commits

Author SHA1 Message Date
Ivailo Monev
2372a3991f kdecore: KLocale optimization
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2024-03-16 19:41:34 +02:00
Ivailo Monev
982afdb961 kdecore: use static string for the default language
QString::fromLatin1() goes trough converter every time

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2024-03-14 01:39:17 +02:00
Ivailo Monev
d923fd1ee8 kdecore: minor KLocale optimizations
QLocale::name() concats strings while QLocale::language() returns the value
of internal private member thus there will be less memory allocations

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2024-03-14 00:18:45 +02:00
Ivailo Monev
6dbd6b5a8e kdecore: update note in KLocale::formatNumber()
kcalc is no more, the plasma applet (which i rewrote too) is there for such
things. for complex operations there is the plasma (krunner) plugin

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2024-03-14 00:05:17 +02:00
Ivailo Monev
d254c051ed kdecore: do not insert the solid_qt catalog by default
that means to get the translations linking to solid library or calling
KGlobal::locale()->insertCatalog("solid_qt") is required

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 02:20:43 +03:00
Ivailo Monev
7f628f95f6 kdecore: pass the QByteArray objects size to QString constructors in KCmdLineOptions and KLocalizedString
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-30 21:23:50 +03:00
Ivailo Monev
453680e04d kdecore: do not store the KCatalog object as KuitSemantics member
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-27 20:46:25 +03:00
Ivailo Monev
8bc18c9962 kdecore: do not output entities from KCmdLineArgsStatic::parseAllArgs()
the output goes to the TTY and there is no rich text handler there, note
that the plain format for the "email" tag also contained entities (even
before the KuitSemantics reimplementation)

because the plain format for the "email" tag

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-20 19:20:12 +03:00
Ivailo Monev
f56c50e41a kdecore: drop redundant "emphasis" markup tag
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-19 23:28:54 +03:00
Ivailo Monev
ddc3476e83 kdecore: KuitSemantics::format() optimization
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-18 23:38:25 +03:00
Ivailo Monev
5e6bc849e0 kdecore: break once format matches the context in KuitSemantics::format()
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-18 23:31:36 +03:00
Ivailo Monev
76ced36171 kdecore: KuitSemantics::format() optimization
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-18 20:04:16 +03:00
Ivailo Monev
591849f4e2 kdecore: KLocalizedString documentation review
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-18 18:55:51 +03:00
Ivailo Monev
53cef8e793 kdecore: break the tag search on bogus tag in KuitSemantics::format()
because the tag will not be replaced in that case and will result in
infinite loop otherwise

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-18 01:02:51 +03:00
Ivailo Monev
cef5ea6e46 kdecore: drop non-operational "application" markup tag
it was not applying any formatting before the reimplementation thus it is
simply redundant

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-18 00:55:14 +03:00
Ivailo Monev
686ba65a7e kdecore: drop redundant "para" markup tag
not used in plain context, same as "p" in rich context. also now Katie will
detect the paragraphs as rich text

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-18 00:39:06 +03:00
Ivailo Monev
ae66400fc7 kdecore: drop redundant "nl" markup tag
not used in plain context, same as "br" in rich text

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 23:34:50 +03:00
Ivailo Monev
f1217c0e64 kdecore: likely KuitSemantics::format() branch optimization
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 23:08:48 +03:00
Ivailo Monev
f8f390c86f kdecore: add "markup" section to the KLocalizedString documentation topics
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 23:08:26 +03:00
Ivailo Monev
1c6ce50933 kdecore: drop support for overriding numbers localization via numid tag
fun fact: there is CLDR data for ~1000 languages and only ~50 use different
number system (not "latn")

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 22:08:20 +03:00
Ivailo Monev
224e42fc3a kdecore: remove unused KLocalizedStringPrivate::substituteSimple() argument
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 19:54:31 +03:00
Ivailo Monev
86025d2c8a kdecore: pass the number width and fill character to KuitSemantics from KLocalizedString
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 19:43:51 +03:00
Ivailo Monev
528f427c67 kdecore: adjust expected results in KLocalizedString tests
text with "&lt;" in it is considered as rich text by Qt::mightBeRichText()
as special case. also entities are not markup and shall not be handled by
KuitSemantics (there is a class for that - KCharsets). entity is used
only in one place (kde-workspace/kate/part/view/kateviewhelpers.cpp) and it
does not even need special handling by KuitSemantics. so, instead of
slowing the whole markup parsing with redundant and unused feature I've
decided to not support it and even improve Katie's Qt::mightBeRichText()
function

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 18:16:26 +03:00
Ivailo Monev
b7b65494a4 kdecore: KuitSemantics optimizations
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 14:47:37 +03:00
Ivailo Monev
9a5af1214b kdecore: reimplement KuitSemantics
is interesting how much simpler it can be by assuming that the tags are
strict and by using Qt::mightBeRichText() for the rich text detection.
while mostly compatible (entities are not converted, some tags were not
used and some even did not do anything) it is subject to optimization by
using QStringMatcher or other tricks (like using a separate tag for the
numbers precision)

overall - no regular expression matching, no XML parser is used and does
what the old implementation was doing but with less code. also passes
most tests (the exception is KLocalizedString test case that expect
entities to be replaced)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-17 01:43:12 +03:00
Ivailo Monev
0d2c0aba3f kdecore: remove non-operational KLocalizedString::inContext() method
non-operational since 5185c917de

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-15 01:06:56 +03:00
Ivailo Monev
c6c05c10b4 kdecore: use KStandardDirs::locate() to check for the existence of catalogs
the catalog file must exist, not just the directory

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-11 09:30:35 +03:00
Ivailo Monev
bd063c8b56 generic: remove dead and irrelevant links references
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-10 14:26:19 +03:00
Ivailo Monev
5fb7d39eb2 kdecore: disable KLOCALE_DUMP_UNTRANSLATED by default
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-08 23:42:52 +03:00
Ivailo Monev
4472e87d19 kdecore: add compile-time definition to dump catalogs when translations is not found
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-08 23:41:24 +03:00
Ivailo Monev
4d3d7840f2 kdecore: call KLocalizedString::notifyCatalogsUpdated() only when the catalogs were actually updated
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-07 02:15:02 +03:00
Ivailo Monev
65587af47d kdecore: probe all languages from KLocale::languageCodeToName() and KLocale::countryCodeToName()
for that to work what KConfig expects (the language only) has to be first
in the list, otherwise KConfig returns entries that are actually not in the
set locale (go figure)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-06 18:55:59 +03:00
Ivailo Monev
8bea5c9837 kdecore: set the config locale to the highest priority language from KLocale::languageCodeToName() and KLocale::countryCodeToName()
as noted in de7070d2bb having multiple
languages and matching the correct one for each use case will have to be
tuned

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-02 07:11:08 +03:00
Ivailo Monev
5e51868194 kdecore: const-ify variables in KLocale::translateRaw() methods
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-01 05:18:47 +00:00
Ivailo Monev
886187c647 kdecore: remove unused kdatetime header inclusion
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-01 03:55:47 +00:00
Ivailo Monev
3e6c5f88ba kdecore: remove redundant KDateTime class forward-declration in klocale header
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-08-01 03:53:47 +00:00
Ivailo Monev
acd77cb495 kdecore: replace authors of KLocale
rewritten and improved!

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-30 06:14:31 +03:00
Ivailo Monev
4dc549635a kdecore: update KCatalog documentation
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-29 08:30:50 +03:00
Ivailo Monev
2ffa34c16a kdecore: update KLocale::defaultLanguage() documentation
deffinetly not internal

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-29 08:20:50 +03:00
Ivailo Monev
ecc721b59c kdecore: change locale language from KLocale::reparseConfiguration() of default KLocale objects
default as in no explicit language has been passed as argument to KLocale
and the language comes either from config or the environemnt variables

with this change KCalendarWidget properly adapts to KLocale config change,
however other applications and widgets may not which is something that has
to be looked into. note that logout is (and was before the KLocale rewrite
even) recommended by the locale KCM for the change to fully take effect

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-29 08:08:13 +03:00
Ivailo Monev
d02d2b3fa4 kdecore: implement precision field for KuitSemantics
otherwise KLocale::formatNumber() has to guess the precision that was
passed to KLocalizedString::subs() and make up a localized integer string
with a magic wand, the precision for precise number types (e.g. ulong,
qlonglong, etc.) remains -1

fixes KSignalPlotter test case failure

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 15:45:04 +03:00
Ivailo Monev
f04d336bc0 kdecore: more compat bits for KLocale::formatNumber()
one more hack comming right up..

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 15:38:13 +03:00
Ivailo Monev
8d3cf0ad3d kdecore: compat bits for KLocale::formatNumber()
the test case for this is in a KSignalPlotter test, see:
kde-workspace/libs/ksysguard/tests/signalplottertest.cpp

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 14:38:05 +03:00
Ivailo Monev
c4a5205981 kdecore: correct milisecond(s) spelling
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 13:20:53 +03:00
Ivailo Monev
d47978309e kdecore: replace the "ok" argument of KLocale::readDate() and KLocale::readTime() with "format" one
beware that bad things will happen if the input strings are not in one of
the formats KLocale::formatDate() and KLocale::formatTime() output

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 12:54:53 +03:00
Ivailo Monev
de7070d2bb kdecore: return only the language part from KLocale::language()
e.g. "bg" for "bg_BG", the default locale is special case for that method
too because of expectations in other places (such as KConfig, KMimeType
tries to match all of the languages returned by KLocale::languageList()
which is how it should be done but that is for another commit)

that is essentially the last bit to bring it back to a compatible state
with the previous implementation, except now more locales are supported

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 12:28:08 +03:00
Ivailo Monev
476f006aab kdecore: do not insert duplicate catalogs into KLocale
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 11:57:30 +03:00
Ivailo Monev
c44da5428f kdecore: do not insert and remove catalogs from KPluginFactory
already done by KComponentDataPrivate, when the component is created and
deleted

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 10:04:36 +03:00
Ivailo Monev
95ccbcb31b kdecore: do not insert invalid catalogs into KLocale
to optimize translation lookup, also re-purposed
KCatalog::catalogLocaleDir() for that

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 10:02:57 +03:00
Ivailo Monev
b1ffffeb89 kdecore: preserve manually inserted catalogs on KLocale configuration reparse
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-07-28 06:21:00 +03:00