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

Feature homonyms translations #103

Merged
merged 7 commits into from
Oct 1, 2014
Merged

Feature homonyms translations #103

merged 7 commits into from
Oct 1, 2014

Conversation

cristiano2lopes
Copy link
Contributor

Relative to issue #53 .

…h gettext msgctxt

base functionality on catalog, added attribute translate-context to
directive and handled possibility of extra argument in the translate
filter.

Tests added for filter catalog and directive.
@cristiano2lopes
Copy link
Contributor Author

There are indeed changes to the catalog. The reason I did it this way instead of prepending or appending the context in the key is related with possible collisions and choosing the right separator for it.

In my opinion this is the right way to do it but I'am willing to abandon it if strong practical reasons arise.

I know that this has more impact on the gettext-tools (currently working on that). If you think the custom prefix approach is better i can change it if that avoids lots of work in the tools.

@@ -17,6 +17,13 @@ describe("Directive", function () {
catalog.setStrings("af", {
"This link: <a class=\"extra-class\" ng-href=\"{{url}}\">{{url}}</a> will have the 'ng-binding' class attached before the translate directive can capture it.": "Die skakel: <a ng-href=\"{{url}}\">{{url}}</a> sal die 'ng-binding' klass aangevoeg hê voor die translate directive dit kan vasvat."
});
catalog.setStrings("pt-BR", {
Developer: [{ male: "Programador", female: "Programadora" },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work if I have <span translate>Developer</span> somewhere else in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will just return Developer (if not in debug mode). See Line 50 .
It's just like it is not translated. Because per gettext specification if 2 equal msgid exists every entry must have a context, if you don't provide a context i consider that case as a non translated string.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, that's an annoying constraint. Certainly something we should document well.

I've been thinking we should add a validation mode to flag common errors, this is certainly one check we should include there as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think about it there is no way of disambiguate it. It would be an arbitrary choice. As is indicates that something is missing just like a missing translation.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because per gettext specification if 2 equal msgid exists every entry must have a context, if you don't provide a context i consider that case as a non translated string.

I've been trying to find a reference for this but couldn't find one. Do you have a source for this?

Sounds like a very annoying restriction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubenv
Copy link
Owner

rubenv commented Sep 5, 2014

I'm afraid we have a problem. Have a look at #104. I'd love to have plural support for filters, but that would be incompatible with these changes.

Not sure yet how we can combine the two

@cristiano2lopes
Copy link
Contributor Author

Hum. I think we have to pass an object with the arguments as properties. The problem is in the tools really.

I will make the change to use an object as an argument to the filter but I will not be able to implement the extraction on the tools. Right now I've implemented the extraction (except for the filter see) and will soon implement the compile.

I can't spent more time right now (maybe later) implementing the filter extraction in the tools as is not a priority (you can bind the attribute to a property and use getPlural to set the value).

@cristiano2lopes
Copy link
Contributor Author

  • Fix identation
  • Use angular.isObject
  • Use null to ignore argument
  • Use angular isArray
  • Change filter argument to an object with property translate-context

Will try to do this today and modify the compile in the tools tomorrow.

and translateContext properties and calls the appropriate catalog method

This change allows more flexibility to accept functionality like #104
Previously the format of the catalog for translations with context was
[{ctxA: t1, ctxB: t2}, {ctxA: t1_plural, ctxB: t2_plural}] which was not
very clever (duplicate info, bad structure, sorry!).

Now the format is the more concise [{ctxA: [t1, t1_plural], ctxB: [t2, t2_plural]}].

The wrapping arrays in the context object values are mandatory even if
only one element is present (no plurals).

The external array wrapping is optional but allowed to achieve
consistency with how things were already done before context
translations were allowed.
@rubenv
Copy link
Owner

rubenv commented Oct 1, 2014

I've been thinking about this and it should be possible to combine the two.

My initial idea was that plural filters should look like this:

{{"1 car" | translate:n:"$count cars"}}

This would be incompatible with this pull request.

It can all be resolved by naming the plural filter translatePlural:

{{"1 car" | translatePlural:n:"$count cars"}}
{{"1 car" | translatePlural:n:"$count cars":"context"}} // With a context

Let's get this merged :-)

@rubenv rubenv merged commit e649412 into rubenv:master Oct 1, 2014
rubenv added a commit that referenced this pull request Oct 1, 2014
No plural filter support yet.
@rubenv
Copy link
Owner

rubenv commented Oct 1, 2014

I've merged this with a simple string syntax. Next up is the tools support.

@rubenv
Copy link
Owner

rubenv commented Oct 1, 2014

Correction: I've merged this to the contexts branch. We can't put this in master until there's tools support (it won't work anyway).

@cristiano2lopes Apologies for this taking so long, I've been very busy with project work (and I'll be out on a vacation soon, so more delays expected :-/ )

@rubenv
Copy link
Owner

rubenv commented Oct 1, 2014

@cristiano2lopes Nonetheless, excellent work this adds real functionality, so happy to see it come in.

Next steps: see #53.

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