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

Add fallback when loading lang file #67

Merged
merged 1 commit into from
Oct 29, 2021

Conversation

necrophidia
Copy link
Contributor

Description

The lang files in the lang folder existed in the package, but when retrieved, it will search for the lang folder in the working directory (which is good, especially if you wanted to do some customization for the translations).
This pull-request is intended to add a fallback logic for retrieving the lang file.

Motivation and Context

This is a possible action item for #58 and #54.
Although, you could just copy the lang folder or any lang file you desire to solve the issue.

How Has This Been Tested?

I've added a unit-test to cover the case, but can only cater for negative test-case.
Instead, I've tested at my local by pushing the changes into my forked repo, then testing with another go file with syntax:

prevTime := time.Now().AddDate(0, 0, -3)
registeredAt := carbon.NewCarbon(prevTime)
currentTime := carbon.NewCarbon(time.Now())

difference, err := registeredAt.DiffForHumans(currentTime, false, false, false)
if err != nil {
log.Println(err.Error())
}

log.Println(difference)

Approach

If the working directory does not have the lang file, it will check the downloaded/installed directory of the package from GoPath, then using the lang file from there.

@codecov
Copy link

codecov bot commented Mar 24, 2021

Codecov Report

Merging #67 (e86314f) into master (ce063dd) will increase coverage by 0.94%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage   89.11%   90.06%   +0.94%     
==========================================
  Files           3        3              
  Lines         634      634              
==========================================
+ Hits          565      571       +6     
+ Misses         44       39       -5     
+ Partials       25       24       -1     
Impacted Files Coverage Δ
carbon.go 91.13% <0.00%> (+0.66%) ⬆️
translator.go 65.51% <0.00%> (+6.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70b4d0e...e86314f. Read the comment docs.

Copy link
Contributor

@rntdrts rntdrts left a comment

Choose a reason for hiding this comment

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

Hey @necrophidia!

Thank you for your contribution! I'm sorry for the delay...

I've taken a look at the PR and it seems good to go!

@necrophidia
Copy link
Contributor Author

no worries, @rntdrts :)
thank you for the review.

What can I do so we can merge this pull request?

@rntdrts
Copy link
Contributor

rntdrts commented Oct 29, 2021

no worries, @rntdrts :) thank you for the review.

What can I do so we can merge this pull request?

I'm gonna ask for one more review from someone on the team and after that, we can merge it! 🚀

@necrophidia
Copy link
Contributor Author

nice.. thank you @rntdrts 🙏

Copy link

@sardyy sardyy left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@rntdrts rntdrts merged commit 0168485 into uniplaces:master Oct 29, 2021
@necrophidia necrophidia deleted the hotfix/lang-finder branch October 29, 2021 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants