Skip to content

Commit

Permalink
test: renamed translation files to v2 go-i18n format
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerex committed Jul 5, 2024
1 parent 1907228 commit d7014cd
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 27 deletions.
27 changes: 13 additions & 14 deletions integration/fixup/fixup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ var _ = Describe("fixup", func() {
panic(err.Error())
}

//session = Runi18n("-c", "fixup")
cmd = exec.Command(I18n4goExec, "-c", "fixup")

stdinPipe, err = cmd.StdinPipe()
Expand Down Expand Up @@ -163,11 +162,11 @@ var _ = Describe("fixup", func() {
exitCode := cmd.Wait()
Ω(exitCode).Should(BeNil())

file, err := ioutil.ReadFile(filepath.Join(".", "translations", "en_US.all.json"))
file, err := ioutil.ReadFile(filepath.Join(".", "translations", "all.en_US.json"))
Ω(err).ShouldNot(HaveOccurred())
Ω(file).Should(ContainSubstring("\"Heal the world\""))

chineseFile, err := ioutil.ReadFile(filepath.Join(".", "translations", "zh_CN.all.json"))
chineseFile, err := ioutil.ReadFile(filepath.Join(".", "translations", "all.zh_CN.json"))
Ω(err).ShouldNot(HaveOccurred())
Ω(chineseFile).Should(ContainSubstring("\"Heal the world\""))
})
Expand All @@ -185,11 +184,11 @@ var _ = Describe("fixup", func() {
exitCode := cmd.Wait()
Ω(exitCode).Should(BeNil())

file, err := ioutil.ReadFile(filepath.Join(".", "translations", "en_US.all.json"))
file, err := ioutil.ReadFile(filepath.Join(".", "translations", "all.en_US.json"))
Ω(err).ShouldNot(HaveOccurred())
Ω(file).ShouldNot(ContainSubstring("\"Heal the world\""))

chineseFile, err := ioutil.ReadFile(filepath.Join(".", "translations", "zh_CN.all.json"))
chineseFile, err := ioutil.ReadFile(filepath.Join(".", "translations", "all.zh_CN.json"))
Ω(err).ShouldNot(HaveOccurred())
Ω(chineseFile).ShouldNot(ContainSubstring("\"Heal the world\""))
})
Expand Down Expand Up @@ -234,14 +233,14 @@ var _ = Describe("fixup", func() {
It("Updates the keys for all translation files", func() {
cmd.Wait()

translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "en_US.all.json"))
translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.en_US.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err := common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Ω(mappedTranslations["I like bananas."]).Should(Equal(common.I18nStringInfo{}))
Ω(mappedTranslations["I like apples."]).ShouldNot(Equal(common.I18nStringInfo{}))

translations, err = common.LoadI18nStringInfos(filepath.Join(".", "translations", "zh_CN.all.json"))
translations, err = common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.zh_CN.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err = common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -252,7 +251,7 @@ var _ = Describe("fixup", func() {
It("Updates all the translation", func() {
cmd.Wait()

translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "en_US.all.json"))
translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.en_US.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err := common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -262,7 +261,7 @@ var _ = Describe("fixup", func() {
It("marks the foreign language translations as updated", func() {
cmd.Wait()

translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "zh_CN.all.json"))
translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.zh_CN.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err := common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -284,14 +283,14 @@ var _ = Describe("fixup", func() {
It("adds the new translation and deletes the old translation from all translation files", func() {
cmd.Wait()

translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "en_US.all.json"))
translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.en_US.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err := common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Ω(mappedTranslations["I like bananas."]).Should(Equal(common.I18nStringInfo{}))
Ω(mappedTranslations["I like apples."]).Should(Equal(apple))

translations, err = common.LoadI18nStringInfos(filepath.Join(".", "translations", "zh_CN.all.json"))
translations, err = common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.zh_CN.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err = common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -309,7 +308,7 @@ var _ = Describe("fixup", func() {
It("adds the extra translation", func() {
cmd.Wait()

translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "zh_CN.all.json"))
translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.zh_CN.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err := common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -327,7 +326,7 @@ var _ = Describe("fixup", func() {
It("removes the extra translation", func() {
cmd.Wait()

translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "zh_CN.all.json"))
translations, err := common.LoadI18nStringInfos(filepath.Join(".", "translations", "all.zh_CN.json"))
Ω(err).ShouldNot(HaveOccurred())
mappedTranslations, err := common.CreateI18nStringInfoMap(translations)
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -344,7 +343,7 @@ func storeTranslationFiles(dir string) (files map[string][]byte, err error) {
if !fileInfo.IsDir() {
name := fileInfo.Name()

if strings.HasSuffix(name, ".all.json") {
if strings.HasPrefix(name, "all.") {
path := filepath.Join(dir, fileInfo.Name())
files[path], err = ioutil.ReadFile(path)

Expand Down
6 changes: 6 additions & 0 deletions test_fixtures/fixup/allgood/translations/all.en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"id": "Translated hello world!",
"translation": "Translated hello world!"
}
]
6 changes: 6 additions & 0 deletions test_fixtures/fixup/allgood/translations/all.zh_CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"id": "Translated hello world!",
"translation": "你好世界!"
}
]
6 changes: 0 additions & 6 deletions test_fixtures/fixup/allgood/translations/en_US.all.json

This file was deleted.

6 changes: 0 additions & 6 deletions test_fixtures/fixup/allgood/translations/zh_CN.all.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"path/filepath"

i18n "github.com/maximilien/i18n4go/i18n4go/i18n"
"github.com/maximilien/i18n4go/i18n4go/i18n"
)

var T i18n.TranslateFunc
Expand Down

0 comments on commit d7014cd

Please sign in to comment.