Skip to content

Commit

Permalink
Merge pull request #55 from Aerex/feat/template-file-format
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien authored Jun 16, 2022
2 parents a826e7d + db44e67 commit 9da663f
Show file tree
Hide file tree
Showing 197 changed files with 50 additions and 33,771 deletions.
14 changes: 11 additions & 3 deletions cmds/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func getI18nFile(locale, dir string) (filePath string) {
if !fileInfo.IsDir() {
name := fileInfo.Name()

if strings.HasSuffix(name, locale+".all.json") {
// assume the file path is a json file and the path contains the locale
if strings.HasSuffix(name, ".json") && strings.Contains(name, fmt.Sprintf("%s.", locale)) {
filePath = filepath.Join(dir, fileInfo.Name())
break
}
Expand All @@ -216,8 +217,15 @@ func findTranslationFiles(dir string) (locales map[string][]string) {
if !fileInfo.IsDir() {
name := fileInfo.Name()

if strings.HasSuffix(name, ".all.json") {
locale := strings.Split(name, ".")[0]
if strings.HasSuffix(name, ".json") {
parts := strings.Split(name, ".")
var locale string

for _, part := range parts {
if !strings.Contains(part, "json") && !strings.Contains(part, "all") {
locale = part
}
}

if locales[locale] == nil {
locales[locale] = []string{}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/softlayer/i18n4go
module github.com/maximilien/i18n4go

go 1.17

require (
github.com/maximilien/i18n4go v0.2.6
github.com/nicksnyder/go-i18n v1.4.0
github.com/onsi/ginkgo v1.2.1-0.20160817190735-43e2af1f01ac
github.com/onsi/gomega v0.0.0-20160718190435-9ed8da19f215
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/maximilien/i18n4go v0.2.6 h1:qJfc1pY0E8QAiVwz190blB+FhGB+x/pjOzjdR1/JeIw=
github.com/maximilien/i18n4go v0.2.6/go.mod h1:qGi+vR2xY056r0saPwcQd6LXZH9MJCn7hkpWeof6mMU=
github.com/nicksnyder/go-i18n v1.4.0 h1:AgLl+Yq7kg5OYlzCgu9cKTZOyI4tD/NgukKqLqC8E+I=
github.com/nicksnyder/go-i18n v1.4.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2xBGjv0j365Q=
github.com/onsi/ginkgo v1.2.1-0.20160817190735-43e2af1f01ac h1:sbVlKLGMQkDfebrb0gB3Xfbheid4hTj1RgiDCpXhTXs=
Expand Down
2 changes: 1 addition & 1 deletion i18n4go/i18n4go.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/maximilien/i18n4go/common"
)

const VERSION = "v0.2.4"
const VERSION = "v0.3.4"

var options common.Options

Expand Down
18 changes: 18 additions & 0 deletions integration/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ var _ = Describe("checkup", func() {
})
})

Context("When the translation files is in format all.<lang>.json", func() {
BeforeEach(func() {
fixturesPath = filepath.Join("..", "..", "test_fixtures", "checkup", "fileformat")
err = os.Chdir(fixturesPath)
Ω(err).ToNot(HaveOccurred(), "Could not change to fixtures directory")

session = Runi18n("-c", "checkup", "-v")
})

It("returns 0", func() {
Ω(session.ExitCode()).Should(Equal(0))
})

It("prints a reassuring message", func() {
Ω(session).Should(Say("OK"))
})
})

Context("When there are problems", func() {
BeforeEach(func() {
fixturesPath = filepath.Join("..", "..", "test_fixtures", "checkup", "notsogood")
Expand Down
7 changes: 7 additions & 0 deletions test_fixtures/checkup/fileformat/src/code/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package code

import "fmt"

func main() {
fmt.Println(T("Translated hello world!"))
}
6 changes: 6 additions & 0 deletions test_fixtures/checkup/fileformat/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/checkup/fileformat/translations/all.zh_CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"id": "Translated hello world!",
"translation": "你好世界!"
}
]
31 changes: 0 additions & 31 deletions vendor/github.com/golang/protobuf/proto/LICENSE

This file was deleted.

229 changes: 0 additions & 229 deletions vendor/github.com/golang/protobuf/proto/clone.go

This file was deleted.

Loading

0 comments on commit 9da663f

Please sign in to comment.