Start work on a new welcome screen: manjaro-hello

manjaro-welcome
manjaro-hello

#21

@Neutrino: Am i right if i say that python can only use the language which is set in the environment variable LANG or a default language?

Here an extract of this page.

Thanks to Juha Sahakangas on the #gtk+ IRC channel for providing the explanation: For this particular case the locale module needs to be used instead of gettext. Python’s gettext module is pure python, it doesn’t actually set the text domain in a way that the C library can read, but locale does (by calling libc). So long as that’s done, GtkBuilder already works the way you’re asking it to.

For now, the program use the default locale of user until we find the solution:

self.sys_locale = locale.getdefaultlocale()[0]
locale.setlocale(locale.LC_ALL, self.sys_locale + ".utf8")

The setlocale method require that locale specified must be installed on user system. That’s the problem, because what we want is to permit the user to use the language he wants, in the language selector. (this is important in a live session).

The language selected by user is set in self.preferences(“locale”):

locales = os.listdir(self.locale_path)
locales.append(self.default_locale)
if self.preferences["locale"] not in locales:
    if self.sys_locale in locales:
        self.preferences["locale"] = self.sys_locale
    else:
        self.preferences["locale"] = self.default_locale

#22

What is the problem ?
It’s just time to create a PKGBUILD that copies .mo into /usr/share/locale/
Need help creating the PKGBUILD? (But the tree is currently not good)

Ps: with the .mo in /usr/share/locale/fr/, I have French(my pc language) if I select English and English with the selection of French :confused:


#23

@papajoke:

  • The problem is that the method locale.setlocale() requires locale to be in locales system list

      locale -a
    

For example, if I remove fr_FR.utf8 from this list it can’t load the mo in the folder fr_FR.

  • Yes, I need help with PKGBUILD. (We can talk in private in French if you want).

  • This will be fixed when choice selection will be re-enabled.

EDIT: I’ve just re-enable the language selector. Manjaro-hello restarts with the language selected if locale selected is in user locales list. (see your list with locale -a command).


#24

hard to make a good PKGBUILD
but for test (bad tree: all in /opt/)

pkgname=manjaro-hello-dev
_pkgname=manjaro-hello
pkgver=1.0.0
pkgrel=1
url="https://forum.manjaro.org/t/start-work-on-a-new-welcome-screen-manjaro-hello/13685"
pkgdesc="Manjaro hello"
arch=('any')
license=('GPL')
depends=('gtk3' 'python3')
makedepends=('git')
source=("$_pkgname::git+https://github.com/Huluti/$_pkgname#branch=master")
md5sums=('SKIP')

package() {
  cd "$srcdir/$_pkgname/src"
  #mkdir -p "${pkgdir}/usr/share/${pkgbase}" for pages as manjaro-welcomes
  mkdir -p "${pkgdir}/opt/${_pkgname}"
  mkdir -p "${pkgdir}/usr/bin"

  cp -a * "${pkgdir}/opt/${_pkgname}" # not good !

  sed -i -e '0,/Exec=manjaro-hello/s//Exec=python3 manjaro-hello.py/' ${_pkgname}.desktop
  echo "Path=/opt/${_pkgname}">>${_pkgname}.desktop
  install -D -m644 ${_pkgname}.desktop ${pkgdir}/usr/share/applications/${_pkgname}.desktop
  # todo: move also icon in good folder
  
  ln -s  /opt/${_pkgname}/manjaro-hello.py ${pkgdir}/usr/bin/${_pkgname}
  #chmod +x ${pkgdir}/usr/bin/${_pkgname} not good : make "cd path" before, todo:create a bash file
  mkdir -p ${pkgdir}/usr/share/locale/fr/LC_MESSAGES/
  install -Dm644 locale/fr_FR/LC_MESSAGES/*.mo ${pkgdir}/usr/share/locale/fr/LC_MESSAGES/
}

#25

I get an error now:

python3 manjaro-hello.py
Traceback (most recent call last):
  File "manjaro-hello.py", line 216, in <module>
    ManjaroHello()
  File "manjaro-hello.py", line 61, in __init__
    locale.setlocale(locale.LC_ALL, self.preferences["locale"] + ".utf8")
  File "/usr/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

with

$ locale -a
C
de_DE.utf8
POSIX

And with

$ locale -a
C
de_DE.utf8
en_US.utf8
POSIX

i can see the English one but if i select French i get the error from above.


#26

This is the problem that I have since the start. Its works only if locale is also installed in Manjaro Settings.


#27

There is no need for an installation. The only thing that is needed is temporary another setting of the language. Maybe you can use a low level method or function (_setlocale()(?)) to set another locale?


#28

Well, you can check also our thus installer code for language selection, if some part is useful for that. However the new app looks already great.


#29

@philm: Thank’s for suggestion, I’ll take a look.

EDIT: For now, I have found that part:

def setup_gettext():
    """ This allows to translate all py texts (not the glade ones) """
    gettext.textdomain(APP_NAME)
    gettext.bindtextdomain(APP_NAME, LOCALE_DIR)

    locale_code, encoding = locale.getdefaultlocale()
    lang = gettext.translation(APP_NAME, LOCALE_DIR, [locale_code], None, True)
    lang.install()

Note the “(not the glade ones)”. A possible hack is to not set text in glade but add them for each object by calling set_text method in pure Python. It would be pity. I think this is what you do with the def translate_ui() method.


#30

Hello!

Looks awsome, also with the arc dark theme everything is very readable and nice looking (I would post a screenshot, but after switching language it wont start again as already mentioned)

I removed the cloned folder, but the error persists - where does the selected language get stored?


#31

@Th3Z0ne, just do this:

rm ~/.config/manjaro-hello.json

#32

Thank you!

Nice, how it looks in dark! Like it a lot!


#33

Glad to hear that !


#34

I’ve just succeed to make translation works and without restarting app moreover.
But it’s just a workaround, code is not sexy…


#35

Hey it works, I guess if it’s not introducing some kind of security hole the code must not be pretty? must it? ^^

Do you have to add the translations manually?


#36

@Th3Z0ne:

  • No, this workaround does not add vulnerabilities :slight_smile: . It is just redundant and should be useless.
  • Everything is automated. In fact, I retrieve the content of all elements of the interface and then redefined these with the same content. But, because it is done in pure Python, gettext module is sufficient (no need to use the locale module).

#37

Hey, like how it looks and works by switching languages. It is always good to have documented and well done code. Sometimes the quick and dirty also works. So which open points are there still?


#38

It’s right ! So, I think that soft has all features of manjaro-welcome now.

  • As suggested by @excalibur1234, we could use Transifex to manage translations.
  • The PKGBUILD need to be improved. (icon path, autostart path, glade path, loop for languages). This will cause small changes in the code.
  • Review pages to check spelling.
  • Test it in all situations (autostart, live systems, delete config files, …)

I think it’s all. The goal was to make manjaro-hello to have all features of manjaro-welcome but with a translation system for the first version.


#39

I think it’s nearly pefect. The only thing that is not needed: The menu on the left because you can reach all pages over the buttons (“Documentation” on the left menu and the button “Read me” are the same page). But the issue is: It is needed to go back to the welcome-screen.


#40

I could resolve this in adding a home icon next to languages selector.
Everyone is ok with this idea ?