-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: default subKeys #37
Conversation
If you agree with this feature, then it would be great if we could merge it quickly and publish a new version |
Seems too much magic to me. Why not use aliases in this case? var langA = {
saveButton: 'Save',
'saveButton:tooltip': '{{saveButton}}',
'saveButton:label': '{{saveButton}}',
cancelButton: 'Cancel',
'cancelButton:tooltip': 'Cancel all the things \ö/'
'cancelButton:label': '{{cancelButton}}',
}
var langB = {
saveButton: 'Save all the things!!',
'saveButton:tooltip': '{{saveButton}}',
'saveButton:label': 'Save',
cancelButton: 'Cancel',
'cancelButton:tooltip': '{{cancelButton}}',
'cancelButton:label': '{{cancelButton}}',
} I imagined the dynamic subkeys as a helper to not have to do this // don't
t('foo:' + bar)
// do
t('foo', bar) |
Aliases add more work/verbosity, not less, for editors/maintainers in the use cases I'm looking at. Some thoughts (as I'm still digesting this)... We already have automatic fallback for non-existent subkeys to a plain-text translation - in cases where the translation has no subkeys at all. This change adds a single explicit way to declare fallbacks for non-existent subkeys generally – i.e. also in cases where the translation is an object with (some, but not all) subkeys. So from a library user's perspective this shouldn't add much more magic than they feel is there already. My use cases include a fairly long list of translation keys, that are 95% of the time just a plain-text string. However there are a few different types of variations that are only required for a few of them (like "abbreviated" form for a couple of outliers) and/or are only required in a single language (i.e. context-sensitive grammatical form/declination). I'm looking for a way to avoid having to normalize all the translations, either on the human-editing end, or by having to write a custom preprocessor for each type/group of translation keys. My hesitation/laziness wrt writing a case-by-case-basis preprocessor was mainly triggered because doing this at runtime seemed to fit kind of neatly in with what is already happening, it runs very fast, and requires only a minimal change to the library. However, I am very much aware of my own objections to adding magic and feature bloat. I'm going to think about this over the weekend |
Any findings? If not I would close that |
I still find this feature an appealing idea. One thing I just realized is that this also perfectly mirrors the magic wildcard However I think the magic default subkey should be named |
I just ran into a case, where I need this :D So if you want to rebase this on current version I would merge it and release a new version. I'm happy with |
Great. Will do later today. |
9ffffef
to
c195b05
Compare
I reverted (reset) the |
I've found this to be very useful - since it allows incrementally upgrading plain translation strings to subkeyed objects, without requiring rewrite of existing code which may rely on the original simple translations.
It also allows less/looser normalization of translation objects, which leads to less need for pointless repetition/verbosity for users maintaining/editing translation files.
This closes the circle on the feature where subkeys are ignored for plain-text translations 08c36f6
This change has slight impact on raw performance (
isObject
check for all translations), but the added power/flexibility far outweighs it IMO.Given these translations:
All of these work equally well: