Skip to content
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

translatePlural and translateContext #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gabegorelick
Copy link
Collaborator

Strawman.

Replaces #148, #122.

Example:

<div>{{ 'Message' | translateContext:'verb' | translatePlural:'count':'$count boats' | translate }}</div>

Caveats:

  • current implementation wraps string primitives in String objects which means you have to terminate the sequence of filters with translate so it can return an actual string primitive.
  • Have to use $count instead of {{$count}} as previously discussed in Add translatePlural filter #122.
  • No interpolation, for same reason

@rubenv
Copy link
Owner

rubenv commented Dec 10, 2014

I must say, the first reaction to this was "what on earth is this?". But it's growing on me. This is actually a really neat and elegant solution to the fact that filters don't take objects.

@gabegorelick
Copy link
Collaborator Author

Thanks. Personally, I'm still not convinced it's the way to go. I'm kind of throwing stuff up to see what sticks. But I'll keep working on it.

@gabegorelick gabegorelick force-pushed the translatePlural branch 3 times, most recently from 07ede21 to 57548a2 Compare December 10, 2014 19:13
@gabegorelick
Copy link
Collaborator Author

Done for now. The only reason you need to terminate the filter chain with translate is because $compile (or $parse or $interpolate or whatever) wraps String wrapper objects in quotes, e.g. foo will become "foo".

I still want to take a look at getting around Angular's parser limitations wrt. the object literal syntax. Maybe leverage a custom directive or something.

@gabegorelick
Copy link
Collaborator Author

If the translate filter is only useful for attributes, then what about a directive to add and translate an attribute? Something like:

<div translate-attr="{foo: {msgid: '', context: ''}}"></div>

or

<div translate-attr translate-attr-foo="{msgid: '', context: ''}"></div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants