Comments (2)
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.
@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)
- [Feature Request] Sorting contribution stats HOT 1
- Only current years commits are used HOT 2
- [Feature Request] Allow _GIT_* variables to be passed as command-line args HOT 1
- Document the Default _GIT_LIMIT value
- Aggregate results based on email instead of name HOT 1
- Ignore Certain Authors HOT 1
- Pathspec for allowlist HOT 1
- [Feature request] Line changes per hour/day/month/etc.
- date does not have a '-j' in ubuntu rather than free BSD
- Count lines added deleted from Merge Commit HOT 1
- Feature Request: Add a file filter HOT 1
- 2.5.1 broken on macos HOT 4
- Broken "git commits by timezone" HOT 2
- Single stats for the same author with multiple username and/or email HOT 2
- Weird output when running none interactive mode
- Wrong output when using Changelogs by author
- test suite doesn't work when running from tarball release
- List changelogs is broken in version 2.5.4 on macos
- Broken on MacOS Sonoma 14.1.1 HOT 9
- Help page does not show when not in git repo
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git-quick-stats.