rubenv / angular-gettext-website

http://angular-gettext.rocketeer.be/
MIT License
0 stars 12 forks source link

Document translation contexts #4

Open rubenv opened 10 years ago

rubenv commented 10 years ago

See https://github.com/rubenv/angular-gettext/issues/53.

Should probably be a page in the advanced section.

A good example is needed here. Someone suggested invoice, which might be a verb or a noun depending on the context.

larvanitis commented 9 years ago

Until this lands in documentation can you please add simple examples here?

I will start with the translate directive which is:

<span translate translate-context="MY_CONTEXT">MY_STRING</span>

How do we use it with gettextCatalog.getString?

rubenv commented 9 years ago

How do we use it with gettextCatalog.getString?

You can use gettextCatalog.getString("My string", null, "context") (the second parameter is an interpolation scope).

Be aware though: I'm not entirely sure those context strings in JS are being extracted already.

larvanitis commented 9 years ago

Tried right before my previous post that way but it was not extracted. Any ETA on that part?

Until it's ready, should I just create a dummy pseudo template with translate directives for the extractor and use the strings later with the getString in js? Is there any more elegant way of doing that?

PS. the code that uses the gettextCatalog directly for translations is outside angular and I don't want to hack manual html compilation just for those translations.

knuhol commented 9 years ago

And what about usage of context in attributes?

<input type="text" placeholder="{{'My string' | translate)}}" />
asmund1 commented 9 years ago

The translate filter uses gettextCatalog.getString() so it should be able to fetch translation by adding context as a parameter to the translate filter:

<input type="text" placeholder="{{'My string' | translate:'Context for my string'}}" />

But the angular-gettext-tools doesn't seem to be able to extract strings that use translate filter with the context attribute added yet. :/

pySilver commented 9 years ago

anyone succees with angular-gettext-tools to extract any context type at all? I've made changes but nothing new extracted.

<span translate-context="Account" translate>Enabled</span>
var foo = gettextCatalog.getString('Failed', null, 'Feed');

Is that not ready yet? (btw +1 to have changelog)

larvanitis commented 9 years ago

At least the first (html attribute) should work with recent versions of gettext. What version do you use and can you try it with latest (2.1.0)?

pySilver commented 9 years ago

@larvanitis @rubenv well I've tried this and nothing got extracted. moreover translation stopped working for phrases annoted using context markers. (yes I'm using latest extrctor and gettext).

rubenv commented 8 years ago

Fixed in #16 by the great @simon04

random-one commented 8 years ago

In my opinion the extraction of a string from Javascript file giving context does not work as expected. I have one word in two angular modules that should be translated differently. Here's what I did:

  1. I added context on both
  2. msgctxt appears in both .po files
  3. Both words appear in the compiled translations.js file that contains the translations of all modules. Result: Only one gets translated properly. The other one is not translated at all.

Any clues on this?