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 #350

Merged
merged 16 commits into from
Nov 23, 2023
Merged

feat: New Localization module #350

merged 16 commits into from
Nov 23, 2023

Conversation

kkumar-gcc
Copy link
Member

@kkumar-gcc kkumar-gcc commented Nov 16, 2023

Closes goravel/goravel#39
Previous PR: #302

📑 Description

This PR(Not Finished) introduces a new Lang facade that can be used to implement localization in your application. To utilize this feature, follow these steps:

  1. Create a lang directory in the root of your project:

    lang/
    |-- en.json
    |-- zn.json
  2. Update your app.go configuration as follows:

    ...
    
    "locale": "zn",
    "fallback_locale": "en",
    
    ...

Now, you can make use of the Lang facade in your code as demonstrated below:

facades.Lang().Get("welcome_message", translation.Option{// key: folder.subfolder.key
	// Locale: "en",
	Replace: map[string]interface{}{
		"name":     "Krishan",
		"location": "India",
	},
})
// Output:
// "welcome_message": "Hello, :name! Welcome to :location."
// Hello, krishan! Welcome to india.

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

ℹ Additional Information

@kkumar-gcc kkumar-gcc mentioned this pull request Nov 16, 2023
4 tasks
Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Attention: 31 lines in your changes are missing coverage. Please review.

Comparison is base (8ad1862) 69.08% compared to head (6a32f3d) 70.04%.

❗ Current head 6a32f3d differs from pull request most recent head 9a8baa3. Consider uploading reports for the commit 9a8baa3 to get more accurate results

Files Patch % Lines
translation/service_provider.go 0.00% 12 Missing ⚠️
foundation/application.go 0.00% 11 Missing ⚠️
foundation/container.go 55.55% 3 Missing and 1 partial ⚠️
translation/file_loader.go 90.24% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
+ Coverage   69.08%   70.04%   +0.95%     
==========================================
  Files         147      151       +4     
  Lines        9922    10332     +410     
==========================================
+ Hits         6855     7237     +382     
- Misses       2598     2624      +26     
- Partials      469      471       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

translation/file_loader_test.go Outdated Show resolved Hide resolved
contracts/foundation/application.go Outdated Show resolved Hide resolved
translation/translator_test.go Outdated Show resolved Hide resolved
foundation/application.go Outdated Show resolved Hide resolved
@devhaozi
Copy link
Member

@kkumar-gcc It seems that you also need to submit the configuration file in the goravel/goravel repository?

@kkumar-gcc
Copy link
Member Author

@kkumar-gcc It seems that you also need to submit the configuration file in the goravel/goravel repository?

Yeah, I need to make some changes in config/app.go file.

contracts/foundation/container.go Show resolved Hide resolved
contracts/translation/translator.go Outdated Show resolved Hide resolved
translation/message_selector_test.go Show resolved Hide resolved
hwbrzzl
hwbrzzl previously approved these changes Nov 22, 2023
Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR!

@hwbrzzl hwbrzzl dismissed their stale review November 22, 2023 08:26

Will test this feature locally.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Nov 22, 2023

Please create another for goravel/goravel.

@kkumar-gcc
Copy link
Member Author

Please create another for goravel/goravel.

Okay, i will create.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Nov 23, 2023

Problem 1:

image

Problem 2:
When the json file is empty or has a wrong formal, need to throw a clear error message, like Laravel:

iShot_2023-11-23_10 36 48

@kkumar-gcc kkumar-gcc enabled auto-merge (squash) November 23, 2023 08:46
@kkumar-gcc kkumar-gcc merged commit a5bf78d into master Nov 23, 2023
8 checks passed
@kkumar-gcc kkumar-gcc deleted the kkumar-gcc/localization branch November 23, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ [Feature] New Localization module
3 participants