-
Notifications
You must be signed in to change notification settings - Fork 560
First round of i18n in acs-engine based on gettext. Subsequent change… #627
Conversation
Note, please don't merge as there will be more commit. |
…s will replace and extract resource strings in acs-engine and make acsengine/api package's i18n used by other go program.
a7459db
to
ecdd9b9
Compare
…anslation resource files.
@@ -29,6 +29,10 @@ RUN git clone https://github.com/akesterson/cmdarg.git /tmp/cmdarg \ | |||
RUN git clone https://github.com/akesterson/shunit.git /tmp/shunit \ | |||
&& cd /tmp/shunit && make install && rm -rf /tmp/shunit | |||
|
|||
# Go tool for internationalization and localization | |||
RUN go get github.com/JiangtianLi/gettext/... \ |
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.
Should ACS Engine be getting stuff from private repos?
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.
I tried not to but I spent some time and didn't find a tool. That package is basically used for extract strings out of source file for translation so it will only run every time we update translation strings. I forked https://github.com/gosexy/gettext to address the parsing we need. I can try to merge into upstream.
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.
I submitted a PR to that tool: gosexy/gettext#16
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.
Just echoing others and calling out we can't include this change as is, the repo has to be publically accessible.
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.
Looks like https://github.com/JiangtianLi/gettext is public now (might have been from the beginning), so we're OK to use the fork, as long as we've registered it at https://ossmsft.visualstudio.com/_oss.
cmd/generate.go
Outdated
classicMode bool | ||
noPrettyPrint bool | ||
parametersOnly bool | ||
translationsDirectory string |
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.
Caller should not need to pass translation dir to any command ever. This decreases usability of ACS Engine. This should happen automatically. In fact do we even care of localize ACS Engine commands? Localization is primarily needed for the RP.
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.
You are right, localization of ACS Engine command has lower priority. The primary translation happens in acsengine and api package, for the purpose of RP. I added here for the e2e test and it is nice to have for ACS Engine. For the translationsDirectory parameter, it will not be needed and default to the translation folder if acs-engine is run at the package root directory (I think that's the most used scenario?) It has the issue if go install is used without deploy translation file. Another approach is to used go-bindata to avoid such caveat. I'll look into it first.
cmd/generate.go
Outdated
@@ -18,17 +20,19 @@ const ( | |||
) | |||
|
|||
type generateCmd struct { |
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.
What about deploy and update commands?
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.
Thanks for reminding. I didn't notice that and will address it.
cmd/generate.go
Outdated
@@ -59,6 +64,13 @@ func (gc *generateCmd) validate(cmd *cobra.Command, args []string) { | |||
var caCertificateBytes []byte | |||
var caKeyBytes []byte | |||
|
|||
locale, err := i18n.LoadTranslations(gc.translationsDirectory) |
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.
It seems that a lot of setup is happening even before ACS Engine functions are called. Which means evey time someone needs to use the primary ACS Engine functions (in the commands or RP) these steps need to be followed. IMO this should be as simple as translation dir being passed to InitializeTemplateGenerator. And then everything is setup inside it.
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.
Thanks for the suggestion. The translation init routine includes set the locale, bind to translation directory, and select domain. I thought about the approach of have package level init function and have each exported function call it if it haven't called before. GNU gettext doc has the guidance of how to init in library. However, in our case, the ACS Engine package is called by RP, which serves requests with different language on multiple thread. For example, if InitializeTemplateGenerator is called by the same thread on different language, the locale needs to be updated. If InitializeTemplateGenerator is called by different thread, each thread needs to keep its own locale. If InitializeTemplateGenerator is called by the same thread with the same language, then we don't need to init again. I haven't found a simple way to handle that other than the caller needs to do some initialization and pass the locale in the context (adopting Go context pattern).
…ngtli-translation
…ngtli-translation
@acs-bot test this please |
…ngtli-translation
@acs-bot test this please |
66f6df2
to
f16bb48
Compare
After merge and due to #663, the CRLF changes have been merged and there are much less changes now. |
@JiangtianLi how do we want to proceed with this PR ? |
@shrutir25 It is pending approval. It has been a while so merge is probably needed. |
…ngtli-translation
pkg/api/apiloader.go
Outdated
contents, e := ioutil.ReadFile(jsonFile) | ||
if e != nil { | ||
return nil, "", fmt.Errorf("error reading file %s: %s", jsonFile, e.Error()) | ||
return nil, "", a.Translator.Errorf("error reading file %s: %s", jsonFile, e.Error()) |
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.
Do you need to replace more places with Translater.Errorf
? At least i know i introduced quite a few of them ...
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.
@rjtsdl Yes, the change is incremental and we can to that in several iterations. The bottom line is to get the framework setup so that people can start use it.
@acs-bot test this please |
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.
LGTM, we can iterate later to enforce this to the existing fmt.Errorf
Reviewed 1 of 28 files at r2, 114 of 1420 files at r4, 9 of 16 files at r5, 11 of 33 files at r6, 15 of 18 files at r7. pkg/i18n/i18n.go, line 117 at r7 (raw file):
any example? pkg/i18n/i18n.go, line 127 at r7 (raw file):
any example of using this? test/i18n/i18ntestinput.go, line 8 at r7 (raw file):
these instructions need to be in README.md perhaps under pkg/i18n Comments from Reviewable |
LGTM |
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.
please also add README about how to do the localization.
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.
Hey Jiangtian, some issues:
- some code is copyrighted by you personally
- can't include private Github repos (you mentioned a PR opened for gosexy/gettext to fix this)
- Didn't see any unit tests for the changes
@@ -29,6 +29,10 @@ RUN git clone https://github.com/akesterson/cmdarg.git /tmp/cmdarg \ | |||
RUN git clone https://github.com/akesterson/shunit.git /tmp/shunit \ | |||
&& cd /tmp/shunit && make install && rm -rf /tmp/shunit | |||
|
|||
# Go tool for internationalization and localization | |||
RUN go get github.com/JiangtianLi/gettext/... \ |
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.
Just echoing others and calling out we can't include this change as is, the repo has to be publically accessible.
# Test translations for acsengine package. | ||
# Copyright (C) 2017 | ||
# Jiangtian Li <jiangtianli@hotmail.com>, 2017. | ||
# |
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.
I don't think we can include code that isn't MIT/Apache v2/etc.
# Test translations for acsengine package. | ||
# Copyright (C) 2017 | ||
# Jiangtian Li <jiangtianli@hotmail.com>, 2017. | ||
# |
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.
Copyright problem here too, and other spots. Won't call all of them out.
…ngtli-translation
Review status: 144 of 145 files reviewed at latest revision, 10 unresolved discussions, some commit checks failed. pkg/i18n/i18n.go, line 117 at r7 (raw file): Previously, weinong (Weinong Wang) wrote…
Yes, example is in i18n_test.go pkg/i18n/i18n.go, line 127 at r7 (raw file): Previously, weinong (Weinong Wang) wrote…
Also in i18n_test.go Comments from Reviewable |
Dismissing review as it's been signed off by others.
@acs-bot test this please |
Review status: 123 of 160 files reviewed at latest revision, 10 unresolved discussions. pkg/i18n/translations/default/LC_MESSAGES/acsengine.po, line 4 at r7 (raw file): Previously, seanknox (Sean Knox) wrote…
Discussed with Sean offline. It is generated by poedit and will be modified by loc team. Currently it follows the same as Kubernetes translation files. Comments from Reviewable |
Review status: 123 of 160 files reviewed at latest revision, 10 unresolved discussions. pkg/i18n/translations/en_US/LC_MESSAGES/acsengine.po, line 4 at r7 (raw file): Previously, seanknox (Sean Knox) wrote…
The same as other translation file copyright. Comments from Reviewable |
Review status: 123 of 160 files reviewed at latest revision, 10 unresolved discussions. test/i18n/i18ntestinput.go, line 8 at r7 (raw file): Previously, weinong (Weinong Wang) wrote…
Added README.md Comments from Reviewable |
Review status: 123 of 160 files reviewed at latest revision, 10 unresolved discussions. Dockerfile, line 33 at r2 (raw file): Previously, seanknox (Sean Knox) wrote…
Resolved offline. The dependence is all MIT licence. Comments from Reviewable |
@acs-bot test this please |
afad27e
to
68e8ddb
Compare
@acs-bot test this please |
…s will replace and extract resource strings in acs-engine and make acsengine/api package's i18n used by other go program.
This PR is to get preview and feedback. Subsequent change will do the real format in the code.
This change is