Comments (4)
I initially implemented similar functionality in goi18n myself until came to the conclusion the developer must do a few things manually anyway:
- The developer needs to provide the translation in the source locale, which is not extractable from the code if you are using generic ids.
*.untranslated.json
can't contain strings without a translation because the translator needs something to translate- The developer should write a comment to each translation to give the translator more context (I need to add support to the data structure for this). This is not extractable from the code either.
Is it really that cumbersome to add a new string to a project?
{
"id": "settings_title",
"translation": "Settings"
}
from go-i18n.
The strings in the source locale can be self-identifying, i.e. the string "Settings" can also be an ID for "Settings". I haven't given much thought about how could plurals be identified yet, but at least we can know when Tfunc is called with extra parameters and treat these as plurals.
Handling comments is also easy to solve by convention. The tool can look for adjacent comments that start with some predefined (or configurable) prefix and transplant those:
// L10N: please leave %s in the translation
T("Error %s", err)
$ goi18n -sift src/ -comments="L10N" *.json
->
{
"id": "Error %s",
"translation": "Error %s",
"comment": "please leave %s in the translation"
}
I didn't really understand what do you mean by a second bullet point.
Adding new strings to the project is bearably cumbersome, but it's error prone. If you add a string to the code, but not to translation files, the only way to discover that is to have a bug in production, whereas the problem is mostly (if not completely) solvable by tooling.
from go-i18n.
It is better if the id is distinct from the source translation
Your source translation might be very long:
T("This awesome new product enables turnkey solutions to your enterprise cloud software development stack and accelerates the synergies at you company to an unprecedented velocity blah blah blah")
T("productDescription") // better
You might need a word translated differently in different contexts (e.g. a homograph):
T("Update") // noun
T("Update") // verb
// Better
T("update.noun")
T("update.verb")
There might be a valid reason to pass a variable to the T function, which would prevent the string from being extracted
productDescription := "This awesome new product enables turnkey solutions to your enterprise cloud software development stack and accelerates the synergies at you company to an unprecedented velocity blah blah blah"
...
T(productDescription)
Other questions you would need to think about:
- How do comments work in Go?
- How do comments work in templates?
- If the same string has two different comments, which one is used? Are they concatenated?
- How do you specify plural forms without adding unnecessary parameters to the API?
These are only the edge cases that I was able to think of off the top of my head; there might be more.
I would be opposed to any solution that adds unnecessary parameters to the runtime API.
I also don't think it is worth it to invent a new syntax to embed translation metadata in Go comments (comments, pluralizations, etc.) when the developer can just put that data directly in a JSON file. The metadata needs to end up in the JSON file anyway.
I think having a consistent workflow is paramount, so any tooling solution should solve all of the use cases mentioned above without any surprising edge cases. I don't see an eloquent solution, so I would rather error on the side of consistency and simplicity.
from go-i18n.
Hmm. Well I approached this along a line of thought that if gettext can do that in C, it should certainly be possible for us to do in Go :-)
I guess I'll pursue this goal as a separate project at least as far as my own needs go and then we can check again on which issues still stand out.
Thanks for your feedback!
from go-i18n.
Related Issues (20)
- How to write a library module designed to be consumed by clients requiring i18n support?
- go get -u "github.com/nicksnyder/go-i18n/v2/i18n" # cd /root/go/GOCODE/src/github.com/nicksnyder/go-i18n; git pull --ff-only HOT 2
- Please explain how the user's current language is selected at runtime
- Is there are way to properly handle translation based on gender HOT 1
- Error handling is faulty HOT 3
- Setting the delimiters globally? HOT 2
- How to generate translations for the toml files HOT 3
- Upgrade golang.org/x/text v0.3.8 HOT 1
- `goi18n extract` doesn't seem to work for source file that use generics HOT 3
- Cound you export this function or when translation has error get the original value HOT 7
- Hook to commonly catch errors HOT 4
- Just a review
- Easy wrapper around this library HOT 1
- List fitting problem HOT 3
- merging new translation into existing translations omits the hashes
- [Question] Is there any way for reverse lookup in bundle? HOT 1
- Upgrade golang.org/x/text HOT 1
- Breaks on key description HOT 1
- Expose fields (or add access methods) of MessageNotFoundErr HOT 4
- Support template.Options for setting up missing key behavior HOT 2
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 go-i18n.