Skip to content

Commit

Permalink
Merge pull request #8 from gobuffalo/fix-dep
Browse files Browse the repository at this point in the history
Running `go get -u` breaks fixes #7
  • Loading branch information
markbates authored Jan 31, 2020
2 parents 95b5d23 + 31923ae commit 400acd2
Show file tree
Hide file tree
Showing 30 changed files with 3,201 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: markbates
patreon: buffalo
28 changes: 12 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@ name: Tests
on: [push]
jobs:


tests-off:
name: (GOPATH) ${{matrix.go-version}} ${{matrix.os}}
tests-on:
name: ${{matrix.go-version}} ${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.12.x, 1.13.x]
os: [macos-latest, windows-latest, ubuntu-latest]
env:
GO111MODULE: on
steps:
- name: Checkout code
uses: actions/checkout@v1
with:
fetch-depth: 1
path: src/github.com/${{ github.repository }}
- name: Test
env:
GOPATH: ${{runner.workspace}}
run: |
go mod tidy -v
go test -cover -race ./...
- name: Checkout Code
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Test
run: |
go mod tidy -v
go test -race ./...
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
.vscode/
.vscode/
testdata/output
File renamed without changes.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module github.com/gobuffalo/mw-i18n
go 1.13

require (
github.com/gobuffalo/buffalo v0.15.3
github.com/gobuffalo/buffalo v0.15.4
github.com/gobuffalo/httptest v1.4.0
github.com/gobuffalo/packd v0.3.0
github.com/nicksnyder/go-i18n v1.10.0
github.com/pelletier/go-toml v1.6.0
github.com/stretchr/testify v1.4.0
gopkg.in/yaml.v2 v2.2.8
)
77 changes: 56 additions & 21 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"strings"

"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/mw-i18n/internal/go-i18n/i18n"
"github.com/gobuffalo/mw-i18n/internal/go-i18n/i18n/language"
"github.com/gobuffalo/mw-i18n/internal/go-i18n/i18n/translation"
"github.com/gobuffalo/packd"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/nicksnyder/go-i18n/i18n/language"
"github.com/nicksnyder/go-i18n/i18n/translation"
)

// LanguageExtractor can be implemented for custom finding of search
Expand Down Expand Up @@ -133,7 +133,7 @@ func (t *Translator) Middleware() buffalo.MiddlewareFunc {

// Translate returns the translation of the string identified by translationID.
//
// See https://github.com/nicksnyder/go-i18n
// See https://github.com/gobuffalo/i18n-mw/internal/go-i18n
//
// If there is no translation for translationID, then the translationID itself is returned.
// This makes it easy to identify missing translations in your app.
Expand Down
9 changes: 4 additions & 5 deletions i18n_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package i18n_test

import (
"github.com/gobuffalo/packd"
"io/ioutil"
"log"
"os"
Expand All @@ -10,10 +9,12 @@ import (
"testing"
"time"

"github.com/gobuffalo/packd"

"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/httptest"
"github.com/gobuffalo/mw-i18n"
i18n "github.com/gobuffalo/mw-i18n"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -217,7 +218,6 @@ func Test_i18n_URL_prefix(t *testing.T) {
r.Equal("Hello, World!", strings.TrimSpace(res.Body.String()))
}


func Test_i18n_TranslateWithLang(t *testing.T) {
r := require.New(t)

Expand Down Expand Up @@ -257,13 +257,12 @@ func Test_i18n_TranslateWithLang(t *testing.T) {
// Test French format-loop
original = "test-format-loop"
want = "M. Mark Bates"
params := struct{FirstName, LastName string}{"Mark", "Bates"}
params := struct{ FirstName, LastName string }{"Mark", "Bates"}
res, err = transl.TranslateWithLang(lang, original, params)
r.NoError(err)
r.Equal(want, res)
}


func Test_Refresh(t *testing.T) {
r := require.New(t)

Expand Down
5 changes: 5 additions & 0 deletions internal/go-i18n/CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feb 24, 2015
- Add Korean

Feb 18, 2015
- Added ParseTranslationFileBytes so translation files may be loaded from an arbitrary serialization format, such as go-bindata.
19 changes: 19 additions & 0 deletions internal/go-i18n/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2014 Nick Snyder https://github.com/nicksnyder

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
186 changes: 186 additions & 0 deletions internal/go-i18n/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
go-i18n [![Build Status](https://travis-ci.org/nicksnyder/go-i18n.svg?branch=master)](http://travis-ci.org/nicksnyder/go-i18n) [![Sourcegraph](https://sourcegraph.com/github.com/nicksnyder/go-i18n/-/badge.svg)](https://sourcegraph.com/github.com/nicksnyder/go-i18n?badge)
=======

go-i18n is a Go [package](#i18n-package) and a [command](#goi18n-command) that helps you translate Go programs into multiple languages.
* Supports [pluralized strings](http://cldr.unicode.org/index/cldr-spec/plural-rules) for all 200+ languages in the [Unicode Common Locale Data Repository (CLDR)](http://www.unicode.org/cldr/charts/28/supplemental/language_plural_rules.html).
* Code and tests are [automatically generated](https://github.com/nicksnyder/go-i18n/tree/master/i18n/language/codegen) from [CLDR data](http://cldr.unicode.org/index/downloads)
* Supports strings with named variables using [text/template](http://golang.org/pkg/text/template/) syntax.
* Translation files are simple JSON, TOML or YAML.
* [Documented](http://godoc.org/github.com/nicksnyder/go-i18n) and [tested](https://travis-ci.org/nicksnyder/go-i18n)!

Package i18n [![GoDoc](http://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](http://godoc.org/github.com/nicksnyder/go-i18n/i18n)
------------

The i18n package provides runtime APIs for fetching translated strings.

Command goi18n [![GoDoc](http://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](http://godoc.org/github.com/nicksnyder/go-i18n/goi18n)
--------------

The goi18n command provides functionality for managing the translation process.

Installation
------------

Make sure you have [setup GOPATH](http://golang.org/doc/code.html#GOPATH).

go get -u github.com/nicksnyder/go-i18n/goi18n
goi18n -help

Workflow
--------

A typical workflow looks like this:

1. Add a new string to your source code.

```go
T("settings_title")
```

2. Add the string to en-US.all.json

```json
[
{
"id": "settings_title",
"translation": "Settings"
}
]
```

3. Run goi18n

```
goi18n path/to/*.all.json
```
4. Send `path/to/*.untranslated.json` to get translated.
5. Run goi18n again to merge the translations
```sh
goi18n path/to/*.all.json path/to/*.untranslated.json
```
Translation files
-----------------
A translation file stores translated and untranslated strings.
Here is an example of the default file format that go-i18n supports:
```json
[
{
"id": "d_days",
"translation": {
"one": "{{.Count}} day",
"other": "{{.Count}} days"
}
},
{
"id": "my_height_in_meters",
"translation": {
"one": "I am {{.Count}} meter tall.",
"other": "I am {{.Count}} meters tall."
}
},
{
"id": "person_greeting",
"translation": "Hello {{.Person}}"
},
{
"id": "person_unread_email_count",
"translation": {
"one": "{{.Person}} has {{.Count}} unread email.",
"other": "{{.Person}} has {{.Count}} unread emails."
}
},
{
"id": "person_unread_email_count_timeframe",
"translation": {
"one": "{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}.",
"other": "{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}."
}
},
{
"id": "program_greeting",
"translation": "Hello world"
},
{
"id": "your_unread_email_count",
"translation": {
"one": "You have {{.Count}} unread email.",
"other": "You have {{.Count}} unread emails."
}
}
]
```
To use a different file format, write a parser for the format and add the parsed translations using [AddTranslation](https://godoc.org/github.com/nicksnyder/go-i18n/i18n#AddTranslation).
Note that TOML only supports the flat format, which is described below.
More examples of translation files: [JSON](https://github.com/nicksnyder/go-i18n/tree/master/goi18n/testdata/input), [TOML](https://github.com/nicksnyder/go-i18n/blob/master/goi18n/testdata/input/flat/ar-ar.one.toml), [YAML](https://github.com/nicksnyder/go-i18n/blob/master/goi18n/testdata/input/yaml/en-us.one.yaml).
Flat Format
-------------
You can also write shorter translation files with flat format.
E.g the example above can be written in this way:
```json
{
"d_days": {
"one": "{{.Count}} day.",
"other": "{{.Count}} days."
},
"my_height_in_meters": {
"one": "I am {{.Count}} meter tall.",
"other": "I am {{.Count}} meters tall."
},
"person_greeting": {
"other": "Hello {{.Person}}"
},
"person_unread_email_count": {
"one": "{{.Person}} has {{.Count}} unread email.",
"other": "{{.Person}} has {{.Count}} unread emails."
},
"person_unread_email_count_timeframe": {
"one": "{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}.",
"other": "{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}."
},
"program_greeting": {
"other": "Hello world"
},
"your_unread_email_count": {
"one": "You have {{.Count}} unread email.",
"other": "You have {{.Count}} unread emails."
}
}
```
The logic of flat format is, what it is structure of structures
and name of substructures (ids) should be always a string.
If there is only one key in substructure and it is "other", then it's non-plural
translation, else plural.
More examples of flat format translation files can be found in [goi18n/testdata/input/flat](https://github.com/nicksnyder/go-i18n/tree/master/goi18n/testdata/input/flat).
Contributions
-------------
If you would like to submit a pull request, please
1. Write tests
2. Format code with [goimports](https://github.com/bradfitz/goimports).
3. Read the [common code review comments](https://github.com/golang/go/wiki/CodeReviewComments).
License
-------
go-i18n is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
Loading

0 comments on commit 400acd2

Please sign in to comment.