Translate Nemo extension (+ Packaging)

About programming and getting involved with Linux Mint development
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
JoeJoeTV
Level 2
Level 2
Posts: 57
Joined: Tue Mar 24, 2020 6:08 am
Location: Germany
Contact:

Translate Nemo extension (+ Packaging)

Post by JoeJoeTV »

Hello there,

I have recently created a python extension for Nemo to add support for KDE Connect and I would like to add translation to it and maybe a way to package it to a .deb file.

Could someone help with that, since I didn't find anything on this forum?

Thanks in advance!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Image
JoeJoeTV
Level 2
Level 2
Posts: 57
Joined: Tue Mar 24, 2020 6:08 am
Location: Germany
Contact:

Re: Translate Nemo extension (+ Packaging)

Post by JoeJoeTV »

Is there no one that can help me with this?
Image
jmorris84
Level 3
Level 3
Posts: 185
Joined: Mon Mar 19, 2012 6:40 pm

Re: Translate Nemo extension (+ Packaging)

Post by jmorris84 »

I have never wrriten and packaged Python code but a DuckDuckGo search for package python extension to deb file resulted in https://stackoverflow.com/questions/174 ... b#17402676 as the first hit. Does this or any of the other search results help?
JoeJoeTV
Level 2
Level 2
Posts: 57
Joined: Tue Mar 24, 2020 6:08 am
Location: Germany
Contact:

Re: Translate Nemo extension (+ Packaging)

Post by JoeJoeTV »

Thanks for you answer!

I got it working just yesterday actually and just saw your answer. I'm, sorry for not seeing it earlier, i think I have to change the Email settings of the LM forum. I looked at your link, but I don't think it will help with nemo extensions, but I will try that. Thanks anyway!

This is my current solution, for anyone having the same issue:

I used PoEdit to make a .pot file for my extension and the translated .po files, that I put in a subfolder of the one, the extension will be in and then proceeded to add the code.

The directory structure looks as follows:

Code: Select all

/usr/share/namo-python/extensions
  +<extension>.py
  +<extension>/
    +locale/
      +en/ (The language code)
        +LC_MESSAGES/
          +<extension>.mo (The actual translation for the language)
I used this reference to get the basics down for gettext:

Code: Select all

import gettext, locale

locale_dir = os.path.dirname(os.path.realpath(__file__)) + "/<extension>/locale"
locale_domain = "<extension>"
The following code will be used to set the text domain for gettext and has to be added to the beginning every function of the extension class you want to use the gettext.gettext function in.

Code: Select all

# Setup translation
locale.setlocale(locale.LC_ALL, "")
gettext.bindtextdomain(locale_domain, locale_dir)
gettext.textdomain(locale_domain)
_ = gettext.gettext
Then you can use _(<text>) (the function is gettext.gettext, but it is often used as _ for ease of use, i think)

As an example, here is the extension I made: https://github.com/JoeJoeTV/nemo-extension-kdeconnect
Image
Locked

Return to “Programming & Development”