Pull request 1934: AG-24191-blocker-languages
Squashed commit of the following:
commit 00294be24c45724a9b2c7a14226dec9f0bf6d24e
Merge: ef96a6759 84a2991ac
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jul 20 19:45:31 2023 +0300
Merge branch 'master' into AG-24191-blocker-languages
commit ef96a6759b29c8d30c58dfc787aff573b5c7d5e6
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jul 20 19:32:29 2023 +0300
scripts: imp docs
commit d89b4a4e6a49e6fa3f010e7b8dfedf55cea149f0
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jul 20 19:05:38 2023 +0300
scripts: imp code
commit bd4d3a68187099691d91c2736bf816333b843f00
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jul 20 17:54:39 2023 +0300
scripts: add blocker languages
This commit is contained in:
parent
84a2991ac2
commit
f9daf72c7e
|
@ -290,7 +290,9 @@ directory.
|
|||
Optional environment:
|
||||
|
||||
* `DOWNLOAD_LANGUAGES`: set a list of specific languages to `download`. For
|
||||
example `ar be bg`.
|
||||
example `ar be bg`. If it set to `blocker` then script will download only
|
||||
those languages, which need to be fully translated (`de en es fr it ja ko
|
||||
pt-br pt-pt ru zh-cn zh-tw`).
|
||||
|
||||
* `UPLOAD_LANGUAGE`: set an alternative language for `upload`.
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ func (c *twoskyClient) download() (err error) {
|
|||
go downloadWorker(wg, failed, client, uriCh)
|
||||
}
|
||||
|
||||
for lang := range c.langs {
|
||||
for _, lang := range c.langs {
|
||||
uri := translationURL(downloadURI, defaultBaseFile, c.projectID, lang)
|
||||
|
||||
uriCh <- uri
|
||||
|
|
|
@ -33,6 +33,22 @@ const (
|
|||
uploadTimeout = 10 * time.Second
|
||||
)
|
||||
|
||||
// blockerLangCodes is the codes of languages which need to be fully translated.
|
||||
var blockerLangCodes = []langCode{
|
||||
"de",
|
||||
"en",
|
||||
"es",
|
||||
"fr",
|
||||
"it",
|
||||
"ja",
|
||||
"ko",
|
||||
"pt-br",
|
||||
"pt-pt",
|
||||
"ru",
|
||||
"zh-cn",
|
||||
"zh-tw",
|
||||
}
|
||||
|
||||
// langCode is a language code.
|
||||
type langCode string
|
||||
|
||||
|
@ -173,14 +189,14 @@ type twoskyClient struct {
|
|||
// uri is the base URL.
|
||||
uri *url.URL
|
||||
|
||||
// langs is the map of languages to download.
|
||||
langs languages
|
||||
|
||||
// projectID is the name of the project.
|
||||
projectID string
|
||||
|
||||
// baseLang is the base language code.
|
||||
baseLang langCode
|
||||
|
||||
// langs is the list of codes of languages to download.
|
||||
langs []langCode
|
||||
}
|
||||
|
||||
// toClient reads values from environment variables or defaults, validates
|
||||
|
@ -208,11 +224,13 @@ func (t *twoskyConfig) toClient() (cli *twoskyClient, err error) {
|
|||
baseLang = langCode(uLangStr)
|
||||
}
|
||||
|
||||
langs := t.Languages
|
||||
langs := maps.Keys(t.Languages)
|
||||
dlLangStr := os.Getenv("DOWNLOAD_LANGUAGES")
|
||||
if dlLangStr != "" {
|
||||
var dlLangs languages
|
||||
dlLangs, err = validateLanguageStr(dlLangStr, langs)
|
||||
if dlLangStr == "blocker" {
|
||||
langs = blockerLangCodes
|
||||
} else if dlLangStr != "" {
|
||||
var dlLangs []langCode
|
||||
dlLangs, err = validateLanguageStr(dlLangStr, t.Languages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -229,19 +247,19 @@ func (t *twoskyConfig) toClient() (cli *twoskyClient, err error) {
|
|||
}
|
||||
|
||||
// validateLanguageStr validates languages codes that contain in the str and
|
||||
// returns language map, where key is language code and value is display name.
|
||||
func validateLanguageStr(str string, all languages) (langs languages, err error) {
|
||||
langs = make(languages)
|
||||
// returns them or error.
|
||||
func validateLanguageStr(str string, all languages) (langs []langCode, err error) {
|
||||
codes := strings.Fields(str)
|
||||
langs = make([]langCode, 0, len(codes))
|
||||
|
||||
for _, k := range codes {
|
||||
lc := langCode(k)
|
||||
name, ok := all[lc]
|
||||
_, ok := all[lc]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("validating languages: unexpected language code %q", k)
|
||||
}
|
||||
|
||||
langs[lc] = name
|
||||
langs = append(langs, lc)
|
||||
}
|
||||
|
||||
return langs, nil
|
||||
|
@ -294,7 +312,15 @@ func summary(langs languages) (err error) {
|
|||
|
||||
f := float64(len(loc)) * 100 / size
|
||||
|
||||
fmt.Printf("%s\t %6.2f %%\n", lang, f)
|
||||
blocker := ""
|
||||
|
||||
// N is small enough to not raise performance questions.
|
||||
ok := slices.Contains(blockerLangCodes, lang)
|
||||
if ok {
|
||||
blocker = " (blocker)"
|
||||
}
|
||||
|
||||
fmt.Printf("%s\t %6.2f %%%s\n", lang, f, blocker)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue