-
Notifications
You must be signed in to change notification settings - Fork 361
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
Support i18n in CC #267
Support i18n in CC #267
Conversation
We have created an issue in Pivotal Tracker to manage this. You can view the current status of your issue at: https://www.pivotaltracker.com/story/show/74023440. |
@MarkKropf i18n in CC would continue the i18n support going into the CLI. I'm moving this to the Runtime tracker. Thanks @xingzhou, |
Thanks @tedsuo, there are still some follow on patches related to this patch. The following patches includes the translations in vendor/error project, the patches of each controller in CC to fully support i18n in CC. I will submit those patches these days, FYI. |
Add the translation files and the translation process description under the newly created i18n folder. The translation is used for the CC i18n enablement work, here is the first patchfor CC i18n enablement: cloudfoundry/cloud_controller_ng#267 Please refer to the README.md included in this patch for more information.
@xingzhou Rather than making a new method in the controller, wouldn't it make more sense to modify the You will need to pull the Dealing with specific error messages in the Errors::ApiError.new_from_details("AppInvalid.instances_less_than_1") and then the yml files could be structured like this: AppInvalid:
instances_less_than_1: "The app is invalid: Number of instances less than 1" |
Hi @jpalermo , thanks for the comments!
|
I guess I'm not clear on what the I18n.locale is a thread local, so each request can have a different value and they won't interfere with each other. When I say message key, I'm referring to the string that gets passed to ApiError. For a key like AppInvalid:
instances_less_than_1: "The app is invalid: Number of instances less than 1"
invalid_app_state: "The app is invalid: Invalid app state provided"
unknown: "The app is invalid: %{errors_messages}" For something like the unknown error case, you'd have to pass in the interpolation values in a hash: Errors::ApiError.new_from_details("AppInvalid", error_messages: e.errors.full_messages) |
at present, translate_validation_exception_of_specific_language is used to transfer the locale info, if we can use I18n.locale, we can directly use it in ApiError without adding such a new method. I finally understood the error message stucture in CC, as there might be two segments in a single error message, I agree that we need to use the 'AppInvalid.instances_less_than_1' style to be the message id. By using this stucture of message id, seems we need to change the controllers code who is using Errors::ApiError.new_from_details method, for this changes, I'm suggesting we can do it later in other subsequent patches gradually. |
Have submitted a change based on the above comments, please take a review, thx |
This patch includes the code to introduce i18n into CC, contains: (1). i18n init code (2). Change the base controller to accept new HTTP_ACCEPT_LANGUAGE param which identifies the locale of request client (3). Enhanced ApiError class to translate the error message for REST API response. This patch does not include concrete REST API controller changes to enable i18n. The changes of concrete REST API controllers' changes will be submitted in other patches.
Submitted some changes for review:
|
|
||
begin | ||
sprintf(I18n.translate(details.name, raise: true, :locale => I18n.locale), *formatted_args) | ||
rescue I18n::MissingTranslationData => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine for now, but once this work is done this rescue should probably be removed so we don't accidentally have any error strings that are not in the translation files.
@jpalermo, yes, I agree with that, I'm thinking that the next patch for CC i18n will be extracting all the messages into vendor/error project and change the title of messages to sth like 'AppInvalid.instances_less_than_1'. Do I need to do something to let this PR merged now? thanks |
Hello, team, anyone can help to push this PR forward? or anything I need to do to get this PR merged? thanks |
@MarkKropf , We have discussed this PR last week, is there anybody from runtime team can take a look at this? I think we have finished the code review for this PR. Thanks! |
thanks @ematpl , anything need I do, please let me know |
This patch includes the code to introduce i18n into CC, contains:
(1). i18n init code
(2). Change the base controller to accept new HTTP_ACCEPT_LANGUAGE param
which identifies the locale of request client
(3). Enhanced ApiError class to translate the error message for REST API
response.
This patch does not include concrete REST API controller changes to
enable i18n. The changes of concrete REST API controllers' changes
will be submitted in other patches.