Repository navigation
Fixes #35: Adds multi-language support to Audimance. #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
640f41c
Fixes #35: The agenda and all views now support multiple languages.
colinbdclark e66b4fc
Merges #36 (Go and module updates) into gh-35.
colinbdclark c9a51b5
Works around git issue in the Nix dev shell on macOS. Fixes lint scri…
colinbdclark cf4d938
Updates D3 to latest version.
colinbdclark be095b3
Refactors Agenda.New to read from an io.Reader. Adds Agenda.Load, whi…
colinbdclark e15d343
Migrates the unit tests to testify.
colinbdclark a5787b8
Moves agenda tests to a new agenda_test package and testing only the …
colinbdclark 3705ec2
Removes redundant logic for returning localized labels.
colinbdclark a1eae44
Factors language resolution into a new internal/i18n package.
colinbdclark 109bd9a
LoadTemplates now takes its views as fs.FS instead of a string.
colinbdclark d0f9a04
Removes Resolve tests that only exercise the upstream language library.
colinbdclark 8079ac2
Generates ETags using hex.EncodeToString instead of fmt.Sprintf().
colinbdclark 8e0c380
Generates the localized Agenda at request time.
colinbdclark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| 18.20.8 | ||
|
|
||
| 26 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package agenda_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/CyCoreSystems/audimance/agenda" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestLabelsFallBackToNames(t *testing.T) { | ||
| a, err := agenda.Load("testdata/no-languages.yaml") | ||
| require.NoError(t, err) | ||
|
|
||
| room := a.Rooms[0] | ||
| assert.Equal(t, "Downstage center", room.PointsOfInterest[0].Label) | ||
| assert.Equal(t, "Choreography", room.Sources[0].Label) | ||
| } | ||
|
|
||
| func TestLocalizedLabels(t *testing.T) { | ||
| a, err := agenda.Load("testdata/bilingual.yaml") | ||
| require.NoError(t, err) | ||
|
|
||
| zh := a.Localized("zh-TW") | ||
| source, original := zh.Rooms[0].Sources[0], a.Rooms[0].Sources[0] | ||
|
|
||
| assert.Equal(t, "編舞", source.Label) | ||
| assert.Equal(t, "Downstage center", zh.Rooms[0].PointsOfInterest[0].Label, "untranslated labels fall back to the name") | ||
| assert.Equal(t, original.ID, source.ID) | ||
| assert.Equal(t, original.Name, source.Name) | ||
| assert.Equal(t, "Choreography", original.Label, "localizing changed the original") | ||
| } | ||
|
|
||
| func TestLabelsDefaultToFirstLanguage(t *testing.T) { | ||
| a, err := agenda.Load("testdata/chinese-first.yaml") | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, "編舞", a.Rooms[0].Sources[0].Label) | ||
| } | ||
|
|
||
| func TestRejectsLabelInUnlistedLanguage(t *testing.T) { | ||
| _, err := agenda.Load("testdata/label-in-unlisted-language.yaml") | ||
| assert.ErrorIs(t, err, agenda.ErrUnlistedLanguage) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| languages: [en, zh-TW] | ||
| rooms: | ||
| - name: stage | ||
| pointsOfInterest: | ||
| - name: Downstage center | ||
| sources: | ||
| - name: Choreography | ||
| labels: | ||
| zh-TW: 編舞 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| languages: [zh-TW, en] | ||
| rooms: | ||
| - name: stage | ||
| pointsOfInterest: | ||
| - name: Downstage center | ||
| sources: | ||
| - name: Choreography | ||
| labels: | ||
| zh-TW: 編舞 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| languages: [en, zh-TW] | ||
| rooms: | ||
| - name: stage | ||
| pointsOfInterest: | ||
| - name: Downstage center | ||
| sources: | ||
| - name: Choreography | ||
| labels: | ||
| zh-Hant: 編舞 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| rooms: | ||
| - name: stage | ||
| pointsOfInterest: | ||
| - name: Downstage center | ||
| sources: | ||
| - name: Choreography |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use
os.Open()instead ofos.ReadFile(), you get anio.Readerback (a file handle), which can be passed directly toNew(). Just make sure you include adefer f.Close()on the returned file handle, so it gets closed after reading. That is handled automatically byos.ReadFile(), but you have to do it yourself foros.Open().