murataydogdu / odata4j

Automatically exported from code.google.com/p/odata4j
0 stars 0 forks source link

Support for internationalization of exception texts #220

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Provide support for internationalization of exception texts which are put into 
an odata error response as message (see chapter 2.2.8.1 in OData v2 
specification) to provide a human readable description of the error.

Original issue reported on code.google.com by mibo.a...@gmail.com on 11 Oct 2012 at 11:04

GoogleCodeExporter commented 8 years ago
I suggest a technical solution based on standard Java internationalization 
techniques (see: http://docs.oracle.com/javase/tutorial/i18n/index.html).

That includes:
 * introducing of ResourceBundles (in "src/main/java/resources")
 * externalization of hard coded texts used during exception creation into these ResourceBundles
 * mechanism to:
  * provide error context information during exception creation 
  * and an simple mapping of those context to according error message in ResourceBundle

Optional:
 * Ensure that an odata error/exception which contains a human readable message can only be created with a mappable error context (and not with an hard coded string).

That (currently) not includes:
 * Any translation work

Original comment by mibo.a...@gmail.com on 11 Oct 2012 at 11:15

GoogleCodeExporter commented 8 years ago
Based on my suggestions I started (cloned) to implement a prototype which 
addresses all features of the _includes_ list.

The source code can be browsed on bitbucket: 
https://bitbucket.org/mibo/odata4j/src/92e75a0062c8/?at=i18n_example

As entry points I suggest:
  * o.o.producer.resources.ExceptionMappingProvider: Mapping of caught exception to ErrorResponse and setting of language for response (from 'Accept-Language' Http-Header).
  * o.o.producer.Responses: Extended {{error}} methods with {{Locale}} parameter and call of new {{MessageService}} for mapping of error context to human readable message.
  * o.o.exceptions.MessageService: Boundary to java {{ResourceBundle}} to provide convenience methods for mapping of error context to human readable message in different languages.
  * o.o.exceptions.NotFoundException: First exception with defines {{Context}} constants and refactored constructors.
  * o.o.exceptions.Context: Interface (abstract class) to define error contexts which are used during exception creation 
  * o.o.producer.resources.EntitiesRequestResource[:93]: Example line in which a {{NotFoundException}} is created with an according context.
  * src/main/resources/i18n*properties: Properties for english and german texts of {{Context}}s defined for {{NotFoundException}}s.

And in odata4j-fit I added some tests:
  * o.o.t.i.globalization.TranslationTest: Several tests for translations

Original comment by mibo.a...@gmail.com on 11 Oct 2012 at 11:46

GoogleCodeExporter commented 8 years ago
As next step I would be happy if I could contribute my enhancements into 
odata4j.
I think an separate branch {{i18n}} would be nice.

Then it is easier to discuss the enhancements and get them in a form to merge 
into the HEAD.

Original comment by mibo.a...@gmail.com on 11 Oct 2012 at 11:51

GoogleCodeExporter commented 8 years ago
Because I can not edit my previous comments here as additional comment the 
linking between above suggested entry points/classes and Bitbucket.

  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/producer/resources/ExceptionMappingProvider.java?at=i18n_example o.o.producer.resources.ExceptionMappingProvider]
  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/producer/Responses.java?at=i18n_example o.o.producer.Responses]
  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/exceptions/MessageService.java?at=i18n_example o.o.exceptions.MessageService]
  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/exceptions/NotFoundException.java?at=i18n_example o.o.exceptions.NotFoundException]
  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c8/odata4j-core/src/main/java/org/odata4j/exceptions/Context.java?at=i18n_example o.o.exceptions.Context]
  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/producer/resources/EntitiesRequestResource.java?at=i18n_example o.o.producer.resources.EntitiesRequestResource:93]
  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/resources?at=i18n_example src/main/resources/i18n*properties]
  * [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-fit/src/test/java/org/odata4j/test/integration/globalization/TranslationTest.java?at=i18n_example o.o.t.i.globalization.TranslationTest]

Original comment by mibo.a...@gmail.com on 11 Oct 2012 at 2:18

GoogleCodeExporter commented 8 years ago
Because I can not edit my previous comments and their is no wiki syntax 
supported I reformatted the above list of links.

  * o.o.producer.resources.ExceptionMappingProvider
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/producer/resources/ExceptionMappingProvider.java?at=i18n_example]

  * o.o.producer.Responses
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/producer/Responses.java?at=i18n_example]

  * o.o.exceptions.MessageService
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/exceptions/MessageService.java?at=i18n_example]

  * o.o.exceptions.NotFoundException
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/exceptions/NotFoundException.java?at=i18n_example]

  * o.o.exceptions.Context
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c8/odata4j-core/src/main/java/org/odata4j/exceptions/Context.java?at=i18n_example]

  * o.o.producer.resources.EntitiesRequestResource:93
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/java/org/odata4j/producer/resources/EntitiesRequestResource.java?at=i18n_example]

  * src/main/resources/i18n*properties
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-core/src/main/resources?at=i18n_example]

  * o.o.t.i.globalization.TranslationTest
    [https://bitbucket.org/mibo/odata4j/src/92e75a0062c878428a594ce87ef64169b15eba28/odata4j-fit/src/test/java/org/odata4j/test/integration/globalization/TranslationTest.java?at=i18n_example]

Original comment by mibo.a...@gmail.com on 15 Oct 2012 at 11:26

GoogleCodeExporter commented 8 years ago
This is a good start - it's an important feature that would make a great 
addition to the project.  Still too raw to accept in the current form.  Can you:
 - Clean up formatting, typos, and commented code?
 - Remove the need for the Context class.  The name is confusing/overloaded, and it's just a multimap, no?
 - We should do a comprehensive sweep of the codebase to externalize any string returned in a response.
 - We should have a good first set of translations.
 - Please post a single patch to bitbucket (so all changes can be seen at once) when you have a change to cleanup your proposal.

Thanks,
- john

Original comment by john.spurlock on 10 Nov 2012 at 6:48

GoogleCodeExporter commented 8 years ago
Hi John,

I also think that it's an important feature  ;o)

I will check your points… 

 - Clean up formatting, typos, and commented code?
=> Sure I will clean up the code. For me this currently is an first request 
whether the concept is ok for an i18n of exception texts

 - Remove the need for the Context class.  The name is confusing/overloaded, and it's just a multimap, no?
=> Yes, it's the mapping between exception text and translated text with a key. 
In addition I added the possibility to add 'values' which are replaced in the 
resulting (translated) error message.
My suggestion is to rename it to 'MessageReference'. I would not drop the 
concept of using an explicit object for mapping. I think this concept is a lot 
easier if we have the wish to have/use translations for all exceptions. 
Otherwise we will get (over time by different developers) exceptions without 
translated messages.

 - We should do a comprehensive sweep of the codebase to externalize any string returned in a response.
=> Also a good idea. In this sweep we could also introduce the concept of the 
'MessageReference' object for all 'exceptions which have messages that should 
be translated'.

- We should have a good first set of translations.
=> Or at least for all exception messages the english text in the resource 
bundles.

 - Please post a single patch to bitbucket (so all changes can be seen at once) when you have a change to cleanup your proposal.
=> I'am new to bitbucket/mercurical so I have to check how I do this  ;o) 
But after the corrections (mentioned above) and if we agree to the resulting 
solution I will create one single patch. Is this OK?

Kind regards, 
Michael

Original comment by mibo.a...@gmail.com on 14 Nov 2012 at 7:50