Closed crisbeto closed 9 years ago
translate
attribute, afterwards it checks if the attribute contains a data binding with the translate
filter, e.g. something="{{ 'Hi' | translate }}"
and only if those 2 conditions don't match, it would check if the attribute is in the list of custom attributes.translate-context
, but it could be a good idea to look for something like custom-attr-context
.IIRC it checks if its a translate attribute, afterwards it checks if the attribute contains a data binding with the translate filter, e.g. `something="{{ 'Hi' | translate }}" and only if those 2 conditions don't match, it would check if the attribute is in the list of custom attributes.
Yes, but what about an extracted string that doesn't use the translate
directive? It's therefore in your POT, but how would it get translated at runtime?
My intention for this was a little simpler: I have a use-case where the attributes get translated inside the directive logic, instead of the attribute. It saves having to add, e.g. placeholder="{{ ::'Translate me' | translate }}"
all the time.
The above example would instead be replaced with placeholder="Translate me"
and somewhere in the directive gettextCatalog.getString(attr.placeholder)
.
OK, that usecase makes sense. I'll let @rubenv way in on the PR though.
It has been a while, @rubenv do you consider this to be good for merging?
My only concern here is that there's no way for this to support plurals and/or contexts. Not sure how to fix that though.
For the extraction it could look for my-custom-attribute-plural
and my-custom-attribute-n
and for the client side it would be up to the developer to implement it via getPlural
.
Ok, that makes sense. I do recommend we add an article with an example of how to use this correctly under the Advanced section of the dev guide: https://angular-gettext.rocketeer.be/dev-guide/
Cool, I'll update my PR. Is the dev guide part of the repo?
Nope, it's over here: https://github.com/rubenv/angular-gettext-website
Done @rubenv, the PR for the site is at https://github.com/rubenv/angular-gettext-website/pull/15.
As an aside: I was wondering whether it would make sense for it to look also for <custom-element>
. It wouldn't be much trouble to add, but I left it out since the PR was about custom attributes.
Sorry if I'm being annoying, but its been a while. Have you had a chance to take a look @rubenv?
@crisbeto Sorry for the super-late reply. This is a super-quality submission, merging!
Released v2.1.3
with this version, will also release a new version of grunt-angular-gettext
so you can explicitely request it.
Also released grunt-angular-gettext 2.1.3
.
Thanks a lot!
And again, sorry for the delays, better late than never!
Also blogged about it: https://rocketeer.be/blog/2015/08/angular-gettext-attributes/
This is a good start, but there are a few questions we need to answer about this behavior.
translate
. Or do you mark every string withtranslate
and your custom attribute?translate-context
is still the marker for contexts. Maybe we should use the same attribute prefix, e.g. if you use the attributefoo
to mark strings for translation, thenfoo-context
would mark your context, instead of (or maybe in addition to?)translate-context
?