Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

First round of i18n in acs-engine based on gettext. Subsequent change… #627

Merged
merged 22 commits into from
Jul 31, 2017

Conversation

JiangtianLi
Copy link
Contributor

@JiangtianLi JiangtianLi commented May 15, 2017

…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 Reviewable

@JiangtianLi
Copy link
Contributor Author

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.
@JiangtianLi JiangtianLi force-pushed the jiangtli-translation branch from a7459db to ecdd9b9 Compare May 16, 2017 22:04
@@ -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/... \
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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).

@JiangtianLi
Copy link
Contributor Author

@acs-bot test this please

@JiangtianLi
Copy link
Contributor Author

@amanohar Can you please take a look? There is line ending issue caused in commit so it appears to have a lot of changes. Although those are benign, I discussed with Cole and will address it later (Cole already has related #650). So please don't merge.

@JiangtianLi
Copy link
Contributor Author

@acs-bot test this please

@JiangtianLi JiangtianLi force-pushed the jiangtli-translation branch from 66f6df2 to f16bb48 Compare June 1, 2017 23:43
@JiangtianLi
Copy link
Contributor Author

After merge and due to #663, the CRLF changes have been merged and there are much less changes now.

@shrutir25
Copy link
Contributor

@JiangtianLi how do we want to proceed with this PR ?

@JiangtianLi
Copy link
Contributor Author

@shrutir25 It is pending approval. It has been a while so merge is probably needed.

@JiangtianLi
Copy link
Contributor Author

@rjtsdl @weinong PTAL

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())
Copy link
Contributor

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 ...

Copy link
Contributor Author

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.

@rjtsdl
Copy link
Contributor

rjtsdl commented Jul 9, 2017

@acs-bot test this please

Copy link
Contributor

@rjtsdl rjtsdl left a 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

@weinong
Copy link
Contributor

weinong commented Jul 11, 2017

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.
Review status: 144 of 145 files reviewed at latest revision, 8 unresolved discussions.


pkg/i18n/i18n.go, line 117 at r7 (raw file):

}

// NT translates a text string into the appropriate plural form, based on GNU's gettext library.

any example?


pkg/i18n/i18n.go, line 127 at r7 (raw file):

}

// NErrorf produces an error with a translated error string in the appropriate plural form.

any example of using this?


test/i18n/i18ntestinput.go, line 8 at r7 (raw file):

)

// This file is used to generate the test translation file

these instructions need to be in README.md perhaps under pkg/i18n


Comments from Reviewable

@weinong
Copy link
Contributor

weinong commented Jul 11, 2017

LGTM
@seanknox as well

Copy link
Contributor

@weinong weinong left a 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.

Copy link
Contributor

@seanknox seanknox left a 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/... \
Copy link
Contributor

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 <[email protected]>, 2017.
#
Copy link
Contributor

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 <[email protected]>, 2017.
#
Copy link
Contributor

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.

@JiangtianLi
Copy link
Contributor Author

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…

any example?

Yes, example is in i18n_test.go


pkg/i18n/i18n.go, line 127 at r7 (raw file):

Previously, weinong (Weinong Wang) wrote…

any example of using this?

Also in i18n_test.go


Comments from Reviewable

@JiangtianLi
Copy link
Contributor Author

@seanknox @anhowe @amanohar PTAL

@amanohar amanohar dismissed their stale review July 26, 2017 18:56

Dismissing review as it's been signed off by others.

@JiangtianLi
Copy link
Contributor Author

@acs-bot test this please

@JiangtianLi
Copy link
Contributor Author

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…

I don't think we can include code that isn't MIT/Apache v2/etc.

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

@JiangtianLi
Copy link
Contributor Author

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…

Copyright problem here too, and other spots. Won't call all of them out.

The same as other translation file copyright.


Comments from Reviewable

@JiangtianLi
Copy link
Contributor Author

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…

these instructions need to be in README.md perhaps under pkg/i18n

Added README.md


Comments from Reviewable

@JiangtianLi
Copy link
Contributor Author

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…

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.

Resolved offline. The dependence is all MIT licence.


Comments from Reviewable

@JiangtianLi
Copy link
Contributor Author

@acs-bot test this please

@JiangtianLi JiangtianLi force-pushed the jiangtli-translation branch from afad27e to 68e8ddb Compare July 31, 2017 18:55
@JiangtianLi
Copy link
Contributor Author

@acs-bot test this please

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants