ejwa / gitinspector

:bar_chart: The statistical analysis tool for git repositories
GNU General Public License v3.0
2.34k stars 324 forks source link

Add an option to select output language manually #203

Closed AlexIII closed 4 years ago

AlexIII commented 4 years ago

I tried to change system language with LANG=..., but it seems to have no effect. In any way, it is not very convenient to change your system language.

adam-waldenberg commented 4 years ago

The standard way for console tools to change language is to simply do,

LANG=en_US gitinspector --help LANG=sv_SE gitinspector --help

This goes for everything, not only gitinspector. If we add an option it would conflict with the standard way of doing things, so I won't do that.

Closing this.

AlexIII commented 4 years ago

Ok, but your command LANG=sv_SE gitinspector --help didn't work for me (ubuntu 18.04 in WSL). I'm guessing it should display help in swedish, but it falls back to english.

adam-waldenberg commented 4 years ago

Are you using the latest stable release or the master branch? I think the master branch needs some additional work with the localization and can have some problems. Also note that you have to use -L --localize-output[=BOOL] to enable localization of the actual output if that's what you are after.

AlexIII commented 4 years ago

I'm using 0.4.3 from ubuntu repos. I realize I need to add -L. Here's the full command that I've tried LANG=sv_SE gitinspector -L -T --grading -F htmlembedded --since=10/28/2019 > stat.html The html output is still in english.

adam-waldenberg commented 4 years ago

That locale probably is not defined then. Try LANG=sv_SE.UTF-8 and see if it makes a difference.

AlexIII commented 4 years ago

It didn't. What do you mean "is not defined"? My system needs to be somehow "aware" of the language I'm trying to use?

adam-waldenberg commented 4 years ago

Yes, the locale has to be supported/enabled on the system. You can read about GNU gettext localization (which is what gitinspector and most other console tools use) here, https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html

To list the supported locales on your system you can execute locale -a. Debian and Ubuntu offer tools to add/generate additional locales to the system if it's missing on yours (via dpkg-configure/reconfigure).

AlexIII commented 4 years ago

I see. locale -a reports that I have ru_RU.utf8. I tried that too, still didn't work...

adam-waldenberg commented 4 years ago

There is no russian translation in gitinspector. Not in 0.4.3 anyway.

adam-waldenberg commented 4 years ago

@AlexIII

The russian translation was never really completed/updated for 0.4.3+ - you can see the status of the tranlsation here,

https://github.com/ejwa/gitinspector/issues/27

Feel free to finish it and contribute a pull request.

AlexIII commented 4 years ago

Ok, I'll look into it and try to figure out what is supposed to be done.

fuhrmanator commented 3 years ago

The standard way for console tools to change language is to simply do,

LANG=en_US gitinspector --help

I'm trying this in Windows 10 with git bash and also in Ubuntu (WSL):

LANG=fr_FR.UTF-8 gitinspector --help

The result is always English for me (as well as if I use it to generate HTML files).

adam-waldenberg commented 3 years ago

@fuhrmanator You need to have that locale enabled in your system for it to pick it up.

Did you try locale -a as mentioned ?

fuhrmanator commented 3 years ago

Yes, locale -a shows fr_FR.utf8 (different from what I was trying). However, even with:

LANG=fr_FR.utf8 gitinspector --help

it's still English. I tried several variants (locale -a shows many for fr). I also tried the sv_SE and others, nothing changes.

adam-waldenberg commented 3 years ago

@fuhrmanator None of this is specific to gitinspector. Try the same for something like the ls command... It should work exactly the same. If it doesn't work for ls it wont work for gitinspector and means you are missing something on your system.

Make sure you are using 0.4.4. Did you install gitinspector via the debian package? If you installed it some other way, maybe it's just unable to find the language files.

An example run of how its supposed to work:

adamw@trappdatorn:~/gitinspector/gitinspector$ locale -a
C
C.UTF-8
de_DE.utf8
en_US.utf8
ko_KR.utf8
POSIX
sv_SE.utf8
adamw@trappdatorn:~/gitinspector/gitinspector$ LANG=de_DE.utf8 ./gitinspector.py --help
Verwendung: ./gitinspector.py [OPTION]... [REPOSITORY]
Zeigt Informationen über das Git-Repository in REPOSITORY. 
Wenn kein Repository angegeben wurde, wird das aktuelle
Verzeichnis verwendet. Wenn mehrere angegeben sind,
wird das letzte verwendet.

Erforderliche Argumente für Langschreibweisen der Optionensind auch
für Kurzschreibweisen erforderlich. Bool'sche Werte (true/false) können
nur mit Langschreibweisen verwendet werden.
  -f, --file-types=ENDUNGEN      Eine kommagetrennte Liste der
                                   Dateiendungen die in die Analyse
                                   einbezogen werden sollen. Standard:
                                   java,c,cc,cpp,h,hh,hpp,py,glsl,rb,js,sql
                                   * bezieht Dateien ohne Endung ein,
                                   ** bezieht alle Dateien ein.
  -F, --format=FORMAT            Definiert das Ausgabeformat der
                                   Analyse. Der Standard ist 'text', verfügbar:
                                   html,htmlembedded,text,xml
      --grading[=BOOL]           Formatiert Statistiken so, dass
                                   sie zur Bewertung von Schülern verwendet
                                   werden können. Alias für -HlmrTw
                                   ....

Standard language on this system is Swedish (which it picks up by default), but I can change to any of the ones listed under locale -a (when a translation is available).

fuhrmanator commented 3 years ago

Ok, it's not working for ls in git bash, so I will pursue that.

For my WSL, there were no locales for French, so I added them using this process and basic commands now work:

$ LANG=fr_FR date
dimanche 12 juillet 2020, 11:32:09 (UTC-0400)

With gitinspector installed with npm it's gitinspector@0.5.0-dev-2 which I use for simplicity with my students who don't code in Python, I see:

$ LANG=fr_FR.utf8 gitinspector --version
gitinspector 0.5.0dev
Copyright © 2012-2015 Ejwa Software. Tous droits réservés.
Licence GPLv3+: GNU GPL version 3 ou ultérieure <http://gnu.org/licenses/gpl.html>.
Le présent logiciel est un logiciel libre: you pouvez le modifier et le redistributer librement.
Il n'y a AUCUNE GARANTIE, dans les limites autorisées par la loi.

Écrit par Adam Waldenberg.

which looks great. However, the --help -L option only shows help in English (seems like a bug).

With -F html it will output in English, but with -F html -L it's in French. Seems like normal behavior. Thanks for helping me figure this out! If I find the git bash solution, I will post here.

On a related note, I have a question: the GNU gettext .po/.mo option for translating (I just learned about it) seems fragile when you change a string in the base language. Do all the the .po files have to be manually changed? Is this why the --help is broken maybe (it's a super long string as a key)?

adam-waldenberg commented 3 years ago

@fuhrmanator

As you figured out - No, it's not a bug. If you want stable translations, please use the stable version (0.4.4). If a string changes (which it has in the master branch, there is no translation available until the language files are updated. I don't recommend using 0.5.0 until it's actually released and marked as final.

Translations are only done just prior to new releases. One of these days I plan on having time to do 0.5.0. Then I will ask the translators to update the language files.

fuhrmanator commented 3 years ago

I did some more digging, and even on the v0.4.4 version --help doesn't work in French. Also, one line ("The following historical commit information, by author, was found.") of the HTML report has an English message (everything else was properly translated). I suspected it was a .mo problem because I couldn't find that precise message anywhere...

I was able to fix both problems in v0.4.4 by re-generating a messages_fr.mo file with Poedit (before compiling, it complained about a few inconsistencies, which I fixed, and I'm not sure if those were also part of the problem). I'm happy to do a PR on the new .po/.mo files (maybe too trivial)?

Would it be possible to get the stable (0.4.4) version of the npm package? The earliest npm version (that I could find) is 0.5.0. This answer might explain how it can be done. Maybe this is moot if you plan to release 0.5.0 soon (seems like it's been baking a long time)? I totally understand the time problem :) Thanks again for your help!