51n7 / kMenu

7 stars 1 forks source link

Localization? #1

Open jmfergeau opened 6 months ago

jmfergeau commented 6 months ago

First of all, thank you for having rebuild this plasmoid !

It would be great to see it in other languages like the old version used to have. I'd be glad to make the french localization for you, if you want. :)

I am completely new to this but i'm gonna eventually try to make the plasmoid localizable on my side.

51n7 commented 6 months ago

Hi @jmfergeau thanks for the feedback!

There are a couple reasons I initially removed localization in the rebuild, one is I have no idea how localization works and documentation has been a real struggle getting this far, and two I plan on making the list of menu items dynamic, so the user can add/remove entries and also use custom text labels which would be written in the users own language, although thinking about it now there would still need to be default text that's translated because I would like the default to exist the way it is now 🤔. I have no idea if a dynamic menu is possible but I plan to dig into this feature next.

I see the pull request, I'll check it out tonight and see if I can make it work.

51n7 commented 6 months ago

@jmfergeau how do feel about this approach as a solution for custom language strings?

I'll still look at your pull request but most of my energy for today has gone into prototyping this.

jmfergeau commented 6 months ago

It's a good idea indeed. Though i'd feel people would prefer to have them in their language by default before eventually change that at will. I'd say putting both would be good, but it might require even more work than just translating imo :p

But since it was your plan from the start, it's up to you. it's your widget after all ^^

51n7 commented 6 months ago

Good points but my first problem is just getting KDE to switch languages for testing:

It looks like this is just broken right now so I might have to wait for the KDE devs to fix language switching. I get every warning and the current language does not change, like even after a reset nothing changes. I'll look at approving your PR just from a static code review maybe but I'd like to test, at least it'll put the initial translation code in place.

jmfergeau commented 6 months ago

Why am I not surprised? xD

For real every time KDE goes to a major version, it runs into huge problems for a whole year before it finally gets stable. I got that from 3 to 4 then 4 to 5 and now this year with 5 to 6. :p

Hope they add more documentation soon tho.

51n7 commented 6 months ago

I've figured out how to automatically generate the necessary files but the plasmoid will not show the translations so I'm starting to wonder if it's just an issue with Plasma still. However if this helps anyone else:

Install gettext

sudo apt install gettext

Scrap QML files for i18n and generate template pot file

create sh file and run: sudo ./messages.sh

#!/bin/sh

# Set the project name
PROJECT="template"

# Set the output directory
podir="po"

# Ensure the output directory exists
mkdir -p $podir

# Debugging output
echo "Extracting translatable strings from QML files..."

# Extract translatable strings from all QML files, specifying the language as JavaScript and encoding as UTF-8
find . -name "*.qml" -print | xargs xgettext --language=JavaScript --keyword=i18n --from-code=UTF-8 -o $podir/$PROJECT.pot

# Check if .pot file was created
if [ -f $podir/$PROJECT.pot ]; then
    echo "Successfully generated $podir/$PROJECT.pot"
else
    echo "Failed to generate $podir/$PROJECT.pot"
fi

Convert .pot to language .po

msginit -i po/template.pot -o po/fr/fr.po -l fr

Convert .po to .mo file

msgfmt po/fr/fr.po -o po/fr/LC_MESSAGES/fr.mo