Skip to content
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

feat: New Localization module #302

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
17b090d
Implement Lang facade
kkumar-gcc Sep 22, 2023
4ffcccb
add IsLocale method
kkumar-gcc Sep 23, 2023
1b165b7
add pluralization support
kkumar-gcc Sep 23, 2023
64ec838
remove context from translator methods
kkumar-gcc Sep 25, 2023
00b7003
add fallback loading of translations
kkumar-gcc Sep 26, 2023
cdcc73b
define a custom type for context key
kkumar-gcc Sep 26, 2023
541019b
set locale in http context
kkumar-gcc Oct 2, 2023
c77479b
Merge branch 'master' into kkumar-gcc/#39
kkumar-gcc Oct 3, 2023
f9d300e
fix: #267 (#306)
devhaozi Oct 3, 2023
482145a
add tests for file loader
kkumar-gcc Oct 4, 2023
72e221e
refactor: move mocks (#307)
devhaozi Oct 5, 2023
4a6e705
build(deps): bump the go-modules group with 1 update (#310)
dependabot[bot] Oct 6, 2023
b1c0268
build(deps): bump the github-actions group with 1 update (#312)
dependabot[bot] Oct 7, 2023
2ecb709
build(deps): bump the go-modules group with 1 update (#313)
dependabot[bot] Oct 7, 2023
1fe58aa
build(deps): bump the go-modules group with 2 updates (#315)
dependabot[bot] Oct 10, 2023
be95246
build(deps): bump github.com/brianvoe/gofakeit/v6 from 6.23.2 to 6.24…
dependabot[bot] Oct 24, 2023
c425f44
build(deps): bump the go-modules group with 6 updates (#326)
dependabot[bot] Oct 26, 2023
74cc654
build(deps): bump the go-modules group with 1 update (#327)
dependabot[bot] Oct 27, 2023
81cd827
build(deps): bump github.com/golang-module/carbon/v2 (#331)
dependabot[bot] Nov 3, 2023
7bfd957
chore: merge v1.13.x to master (#333)
devhaozi Nov 4, 2023
0a38081
Merge v1.13.4 (#345)
hwbrzzl Nov 9, 2023
376f1d9
fix: Validator Bind can't cast value (#336)
devhaozi Nov 10, 2023
6b10569
build(deps): bump the go-modules group with 3 updates (#346)
dependabot[bot] Nov 13, 2023
b3de65f
feat: [#289] Remove github.com/ory/dockertest (#334)
hwbrzzl Nov 15, 2023
7a269f7
remove `maps.Copy` function
kkumar-gcc Nov 15, 2023
09d4514
build(deps): bump the github-actions group with 1 update (#348)
dependabot[bot] Nov 16, 2023
c1af159
build(deps): bump the go-modules group with 1 update (#347)
dependabot[bot] Nov 16, 2023
0f69215
support empty string and new lines in a message for translation
kkumar-gcc Nov 16, 2023
b895b87
add tests for message selector
kkumar-gcc Nov 16, 2023
df11554
finish tests for `MessageSelector`
kkumar-gcc Nov 16, 2023
c7473b3
add test cases for 'Get' method in translator
kkumar-gcc Nov 16, 2023
8722588
Implement Lang facade
kkumar-gcc Sep 22, 2023
6d2c301
add IsLocale method
kkumar-gcc Sep 23, 2023
a384ec5
add pluralization support
kkumar-gcc Sep 23, 2023
2f9cae1
remove context from translator methods
kkumar-gcc Sep 25, 2023
b2dacc6
add fallback loading of translations
kkumar-gcc Sep 26, 2023
620c8f6
define a custom type for context key
kkumar-gcc Sep 26, 2023
5b4aaf4
set locale in http context
kkumar-gcc Oct 2, 2023
114bd36
add tests for file loader
kkumar-gcc Oct 4, 2023
3abc8ac
remove `maps.Copy` function
kkumar-gcc Nov 15, 2023
ea59475
support empty string and new lines in a message for translation
kkumar-gcc Nov 16, 2023
73de8c6
add tests for message selector
kkumar-gcc Nov 16, 2023
402d1a7
finish tests for `MessageSelector`
kkumar-gcc Nov 16, 2023
3f9f66a
add test cases for 'Get' method in translator
kkumar-gcc Nov 16, 2023
a47d468
resolve conflict between master and current branch
kkumar-gcc Nov 16, 2023
97bb8e2
Merge remote-tracking branch 'origin/kkumar-gcc/#39' into kkumar-gcc/#39
kkumar-gcc Nov 16, 2023
72f7ff2
chore: update mocks
kkumar-gcc Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/cr.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/mockery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Mockery
on:
pull_request:
jobs:
mockery:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Mockery
run: |
go install github.com/vektra/mockery/v2@v2.34.2
- name: Generate Mocks
run: |
~/go/bin/mockery --all --keeptree --dir=contracts
- uses: stefanzweifel/git-auto-commit-action@v5
name: Commit changes
with:
commit_message: "chore: update mocks"
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: go mod pakcage cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('go.mod') }}
- name: Install dependencies
run: go mod tidy
- name: Run tests
Expand All @@ -33,7 +38,12 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: go mod pakcage cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('go.mod') }}
- name: Install dependencies
run: go mod tidy
- name: Run tests
run: go test ./... -short
run: go test ./...
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ This project exists thanks to all the people who contribute, to participate in t
<a href="https://github.com/Marian0" target="_blank"><img src="https://avatars.githubusercontent.com/u/624592?v=4" width="48" height="48"></a>
<a href="https://github.com/ahmed3mar" target="_blank"><img src="https://avatars.githubusercontent.com/u/12982325?v=4" width="48" height="48"></a>
<a href="https://github.com/flc1125" target="_blank"><img src="https://avatars.githubusercontent.com/u/14297703?v=4" width="48" height="48"></a>
<a href="https://github.com/zzpwestlife" target="_blank"><img src="https://avatars.githubusercontent.com/u/12382180?v=4" width="48" height="48"></a>
<a href="https://github.com/juantarrel" target="_blank"><img src="https://avatars.githubusercontent.com/u/7213379?v=4" width="48" height="48"></a>

## Sponsor

Better development of the project is inseparable from your support, reward us by [Open Collective](https://opencollective.com/goravel).

<p align="left"><img src="https://www.goravel.dev/reward.png" width="200"></p>

## Group

Expand Down
8 changes: 8 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ Laravel!
<a href="https://github.com/Marian0" target="_blank"><img src="https://avatars.githubusercontent.com/u/624592?v=4" width="48" height="48"></a>
<a href="https://github.com/ahmed3mar" target="_blank"><img src="https://avatars.githubusercontent.com/u/12982325?v=4" width="48" height="48"></a>
<a href="https://github.com/flc1125" target="_blank"><img src="https://avatars.githubusercontent.com/u/14297703?v=4" width="48" height="48"></a>
<a href="https://github.com/zzpwestlife" target="_blank"><img src="https://avatars.githubusercontent.com/u/12382180?v=4" width="48" height="48"></a>
<a href="https://github.com/juantarrel" target="_blank"><img src="https://avatars.githubusercontent.com/u/7213379?v=4" width="48" height="48"></a>

## 打赏

开源项目的发展离不开您的支持,感谢微信打赏。

<p align="left"><img src="https://www.goravel.dev/reward-wechat.jpg" width="200"></p>

## 群组

Expand Down
6 changes: 3 additions & 3 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"gorm.io/gorm/clause"

authcontract "github.com/goravel/framework/contracts/auth"
cachemock "github.com/goravel/framework/contracts/cache/mocks"
configmock "github.com/goravel/framework/contracts/config/mocks"
ormmock "github.com/goravel/framework/contracts/database/orm/mocks"
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/database/orm"
cachemock "github.com/goravel/framework/mocks/cache"
configmock "github.com/goravel/framework/mocks/config"
ormmock "github.com/goravel/framework/mocks/database/orm"
"github.com/goravel/framework/support/carbon"
)

Expand Down
4 changes: 2 additions & 2 deletions auth/console/jwt_secret_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/stretchr/testify/assert"

configmock "github.com/goravel/framework/contracts/config/mocks"
consolemocks "github.com/goravel/framework/contracts/console/mocks"
configmock "github.com/goravel/framework/mocks/config"
consolemocks "github.com/goravel/framework/mocks/console"
"github.com/goravel/framework/support"
"github.com/goravel/framework/support/file"
)
Expand Down
2 changes: 1 addition & 1 deletion auth/console/policy_make_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package console
import (
"testing"

consolemocks "github.com/goravel/framework/contracts/console/mocks"
consolemocks "github.com/goravel/framework/mocks/console"
"github.com/goravel/framework/support/file"

"github.com/stretchr/testify/assert"
Expand Down
32 changes: 16 additions & 16 deletions cache/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/suite"

"github.com/goravel/framework/contracts/cache"
configmock "github.com/goravel/framework/contracts/config/mocks"
logmock "github.com/goravel/framework/contracts/log/mocks"
configmock "github.com/goravel/framework/mocks/config"
logmock "github.com/goravel/framework/mocks/log"
)

type DriverTestSuite struct {
Expand Down Expand Up @@ -74,7 +74,7 @@ func (s *DriverTestSuite) TestStore() {
type Store struct {
}

//Add Store an item in the cache if the key does not exist.
// Add Store an item in the cache if the key does not exist.
func (r *Store) Add(key string, value any, seconds time.Duration) bool {
return true
}
Expand All @@ -83,47 +83,47 @@ func (r *Store) Decrement(key string, value ...int) (int, error) {
return 1, nil
}

//Forever Store an item in the cache indefinitely.
// Forever Store an item in the cache indefinitely.
func (r *Store) Forever(key string, value any) bool {
return true
}

//Forget Remove an item from the cache.
// Forget Remove an item from the cache.
func (r *Store) Forget(key string) bool {
return true
}

//Flush Remove all items from the cache.
// Flush Remove all items from the cache.
func (r *Store) Flush() bool {
return true
}

//Get Retrieve an item from the cache by key.
// Get Retrieve an item from the cache by key.
func (r *Store) Get(key string, def ...any) any {
return key
}

//Get Retrieve an item from the cache by key.
// Get Retrieve an item from the cache by key.
func (r *Store) GetBool(key string, def ...bool) bool {
return false
}

//Get Retrieve an item from the cache by key.
// Get Retrieve an item from the cache by key.
func (r *Store) GetInt(key string, def ...int) int {
return 1
}

//Get Retrieve an item from the cache by key.
// Get Retrieve an item from the cache by key.
func (r *Store) GetInt64(key string, def ...int64) int64 {
return 1
}

//Get Retrieve an item from the cache by key.
// Get Retrieve an item from the cache by key.
func (r *Store) GetString(key string, def ...string) string {
return ""
}

//Has Check an item exists in the cache.
// Has Check an item exists in the cache.
func (r *Store) Has(key string) bool {
return true
}
Expand All @@ -136,22 +136,22 @@ func (r *Store) Lock(key string, second ...time.Duration) cache.Lock {
return nil
}

//Pull Retrieve an item from the cache and delete it.
// Pull Retrieve an item from the cache and delete it.
func (r *Store) Pull(key string, def ...any) any {
return def
}

//Put Store an item in the cache for a given number of seconds.
// Put Store an item in the cache for a given number of seconds.
func (r *Store) Put(key string, value any, seconds time.Duration) error {
return nil
}

//Remember Get an item from the cache, or execute the given Closure and store the result.
// Remember Get an item from the cache, or execute the given Closure and store the result.
func (r *Store) Remember(key string, ttl time.Duration, callback func() (any, error)) (any, error) {
return "", nil
}

//RememberForever Get an item from the cache, or execute the given Closure and store the result forever.
// RememberForever Get an item from the cache, or execute the given Closure and store the result forever.
func (r *Store) RememberForever(key string, callback func() (any, error)) (any, error) {
return "", nil
}
Expand Down
2 changes: 1 addition & 1 deletion cache/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/suite"

configmock "github.com/goravel/framework/contracts/config/mocks"
configmock "github.com/goravel/framework/mocks/config"
)

type MemoryTestSuite struct {
Expand Down
30 changes: 13 additions & 17 deletions config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,31 @@ type Application struct {
}

func NewApplication(envPath string) *Application {
if !file.Exists(envPath) {
color.Redln("Please create " + envPath + " and initialize it first.")
color.Warnln("Example command: \ncp .env.example .env && go run . artisan key:generate")
os.Exit(0)
}

app := &Application{}
app.vip = viper.New()
app.vip.SetConfigType("env")
app.vip.SetConfigFile(envPath)
app.vip.AutomaticEnv()

if err := app.vip.ReadInConfig(); err != nil {
color.Redln("Invalid Config error: " + err.Error())
os.Exit(0)
}
if file.Exists(envPath) {
app.vip.SetConfigType("env")
app.vip.SetConfigFile(envPath)

app.vip.SetEnvPrefix("goravel")
app.vip.AutomaticEnv()
if err := app.vip.ReadInConfig(); err != nil {
color.Redln("Invalid Config error: " + err.Error())
os.Exit(0)
}
}

appKey := app.Env("APP_KEY")
if support.Env != support.EnvArtisan {
if !support.IsKeyGenerateCommand {
if appKey == nil {
color.Redln("Please initialize APP_KEY first.")
color.Warnln("Example command: \ngo run . artisan key:generate")
color.Println("Create a .env file and run command: go run . artisan key:generate")
color.Println("Or set a system variable: APP_KEY={32-bit number} go run .")
os.Exit(0)
}

if len(appKey.(string)) != 32 {
color.Redln("Invalid APP_KEY, please reset it.")
color.Redln("Invalid APP_KEY, the length must be 32, please reset it.")
color.Warnln("Example command: \ngo run . artisan key:generate")
os.Exit(0)
}
Expand Down
Loading