Giter Site home page Giter Site logo

Comments (2)

tomice avatar tomice commented on July 20, 2024

Info dump/thoughts:
The best way I can think of doing this would be to setup a variable for every string, and have separate files in a "lang" folder that get sourced by git-quick-stats. Here is what the directory structure would look like:

ice@PC-PC:~/git-quick-stats(master)$ tree
.
├── Dockerfile
├── foo
├── git-quick-stats
├── git-quick-stats.1
├── lang
│   ├── deu
│   ├── eng
│   ├── epo
│   ├── fin
│   ├── fra
│   ├── jpn
│   └── nld
├── LICENSE
├── Makefile
├── README.md
└── tests
    ├── assert.sh
    └── commands_test.sh

All strings would now be variables sourced from these files that utilize a common variable name. For example, on line 53 in the checkUtils function, "local -r msg" would be changed to "CHECK_UTILS_MSG" and moved to every one of these files. So deu would have "CHECK_UTILS_MSG", eng would have "CHECK_UTILS_MSG", epo would have "CHECK_UTILS_MSG", and so on. CHECK_UTILS_MSG would then equal the appropriate text for that particular language. In eng, it would be:

CHECK_UTILS_MSG="not found. Please make sure this is installed and in PATH."

That means line 53 would be removed and line 59 would be changed to:

command -v "$u" >/dev/null 2>&1 || { echo >&2 "$u ${CHECK_UTILS_MSG}"; exit 1; }

The language could be set via command line similar to how we do _GIT_SINCE and so on. Or we could attempt to parse $LANG to determine the appropriate language. These language files would essentially get sourced at startup.

Opinion:
I usually don't like inserting my personal opinions in these, but I feel this would be extremely difficult to do in bash reliably that would work across various installations of Linux, UNIX, and macOS. A lot of this would be shell encoding specific, as well as locale specific.

Some may wish to have their shell language be a different language from their OS language for various reasons, and that could cause some issues if we try to guess the language via $LANG. A good chunk of the script would need to be rewritten.

I feel this would be better suited for something like Python to handle this, as we could then utilize classes, more robust design patterns, a nice database for all of the languages, and be able to better abstract the random quirks that occur across shell platforms by utilizing Python's built-in libraries instead for most of what we are doing.

I have read this before: https://www.linuxjournal.com/content/internationalizing-those-bash-scripts

And I have tried a quick test with it, but I found it didn't work out too well across different platforms upon my first go.

If anyone has a better idea of how to do this without resorting to a different language such as Python, Ruby, or what have you, I would love to hear it, as this is something I am quite interested in doing reliably.

from git-quick-stats.

arzzen avatar arzzen commented on July 20, 2024

@tomice thank you for your elaboration 👍 ,

I'm adding more options on how to use translate in bash;
You can use the $"…" syntax to specify a string that is to be translated according to the locale. The translations must be in a message catalog file; see the bash manual for where this file is located and the Glibc manual for the format of the file. See practical example here.

But, my personal opinion is that the English translation is quite sufficient, it is generally used.

So, for now, I close this issue.

from git-quick-stats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.