-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New Localization module (#350)
* add localization feature * add test cases for translator * increase test coverage for file_loader * add test cases for the remaining function of translator * add test cases for the remaining function of translator * add set method using http context * chore: update mocks * add SetLocale from http context * chore: update mocks * add assertion for http context in SetLocale * re-order methods in translation contract * fix linting * fix formatting of error for translation --------- Co-authored-by: kkumar-gcc <[email protected]>
- Loading branch information
1 parent
8ad1862
commit a5bf78d
Showing
21 changed files
with
1,655 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 @@ | ||
package translation | ||
|
||
type Loader interface { | ||
// Load the messages for the given locale. | ||
Load(folder string, locale string) (map[string]map[string]string, error) | ||
} |
This file contains 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,32 @@ | ||
package translation | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type Translator interface { | ||
// Choice gets a translation according to an integer value. | ||
Choice(key string, number int, options ...Option) (string, error) | ||
// Get the translation for the given key. | ||
Get(key string, options ...Option) (string, error) | ||
// GetFallback get the current application/context fallback locale. | ||
GetFallback() string | ||
// GetLocale get the current application/context locale. | ||
GetLocale() string | ||
// Has checks if a translation exists for a given key. | ||
Has(key string, options ...Option) bool | ||
// SetFallback set the current application/context fallback locale. | ||
SetFallback(locale string) context.Context | ||
// SetLocale set the current application/context locale. | ||
SetLocale(locale string) context.Context | ||
} | ||
|
||
type Option struct { | ||
Fallback *bool | ||
Locale string | ||
Replace map[string]string | ||
} | ||
|
||
func Bool(value bool) *bool { | ||
return &value | ||
} |
This file contains 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,11 @@ | ||
package facades | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/goravel/framework/contracts/translation" | ||
) | ||
|
||
func Lang(ctx context.Context) translation.Translator { | ||
return App().MakeLang(ctx) | ||
} |
This file contains 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.