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
No grammatical cases in translations #175
Comments
The same problem for Arabic language , words would need to be translated for the different grammatical cases. For Example :- Correct is |
Hey Fellows, this can be done using a custom resource class, example: https://github.com/ocpsoft/prettytime/blob/master/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java Happy to accept a PR that fixes this using these overrides! |
I'll have a look if I can add a custom German resource class. |
@lincolnthree The following code snippets show the logic inside the format() ...
TimeFormat format = getFormat(duration.getUnit());
String time = format.format(duration); // returns "5 Tagen"
return format.decorate(duration, time); // returns "in 5 Tagen" -> correct formatDuration() ...
TimeFormat timeFormat = getFormat(duration.getUnit());
return timeFormat.format(duration); // returns "5 Tagen" -> wrong: should be "5 Tage" As you can see, both methods do the same, with the difference that I could probably solve the issue if I can get that context information inside the Should i try to fix that and send a PR? As statet above, there would be code changes outside of the custom I would appreciate a response in the next few days, thanks! |
Hmm, interesting. I think I see the issue you're describing. Because So... Yes, I can see the need to know when the method is being called via I think adding a context parameter for I think the context should probably be called
Something like that... what do you think? And yes, it would be awesome if you want to take a stab at this. **EDIT: On second thought... why can't this be accomplished via
Thoughts? |
Yeah, unless I'm mistaken, actually it's right there in your example:
formatDuration()
So I think this is totally doable using the current API, you'll just need to reduce the functionality of "format", and use decorate to do the rest of the work. |
Here's a better example of doing this in a Resource bundle, using the So, I could be wrong, but I still think this is possible to do without modifying the existing codebase. But... if you still think it would be cleaner to do this by changing the internal code, I'm happy to listen. |
Yeah, that could solve the problem. But it would put in question if I'm aware about backwards compatibility, so I will definitely keep that in mind when opening a PR :)
I'm not sure if I understand. Do you mean that the While this might work for the issues I've mentioned in German, this seems like a dirty workaround. It's just lucky for us that all the problems I've found for German can be solved that way, because their plural all end with an I also don't expect the issue in the Arabic language, which was mentioned above, could be solved that easily. But I don't know anything about Arabic, so I might be wrong. Or did I understand your proposal incorrectly? |
Yes, that's right. That's the original intent of the separation between format & decorate methods. This ( I think it makes sense to me to provide a custom I'm still open to a PR that exposes extra contextual information if you think it will make for a cleaner solution, but I worry about API explosion, where we're now adding another 4 methods on the TimeFormat API just to provide information for one language resource bundle, when a solution already exists in the current API. I also worry about performance overhead of creating new context objects on every call to Thoughts? |
Yeah, I understand your concerns. I opened a PR fixing the issues I initially reported. I must say that it felt quite a bit bad to solve it in this "dirty" way, but I agree with you that restructuring the core classes just because of one language isn't a great idea. But I've seen that there are quite a few unresolved issues. If some of them are unresolved because they can't be resolved very easily with the current API, it might be worth thinking about some restructuring. But I know that the API structure probably isn't what is holding those issues back 😄
|
Thanks so much! I'll review it ASAP. Like I said, I'm still willing to entertain a PR that addresses the concerns you have with the API, but I just want to make sure the discussion about it was comprehensive and included potential issues that might occur. |
Sorry for the delay @hertg . Releasing version 5 now, including this update. |
Note: Java 8 will now be required. |
When using the
formatDuration(Date)
method inLocale.GERMAN
the translations are not accurate.Problem
5 Tagen
should be5 Tage
5 Monaten
should be5 Monate
5 Jahren
should be5 Jahre
5 Jahrzenten
should be5 Jahrzente
5 Jahrhunderten
should be5 Jahrhunderte
5 Jahrtausenden
should be5 Jahrtausende
However
These words are correct for the
format(Date)
method.Example:
vor 5 Tagen
vor 5 Monaten
Explanation
Nouns do have a case (Kasus) when used in a sentence in german (and some other languages?).
(see https://en.wikipedia.org/wiki/Grammatical_case)
This means that words would need to be translated for the different grammatical cases.
Instead of just this translation:
You'd need to have these:
Which would be very annoying.
Possible Solution
You should translate whole sentences and parameterize them instead of trying to translate single words and then later sticking them together, because that will result in errors like these in the long term.
Highly relevant video: https://www.youtube.com/watch?v=GAgp7nXdkLU
The text was updated successfully, but these errors were encountered: