fix: generate i18n_resource binary file for user on rewrite-package #131
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.
Context
Currently,
i18n4go
expects the user to generate a binary file of the translations file (usinggo-bindataa
) prior to running therewrite-package
comand. This will lead to runtime errors for the updated source code if the generated go file (i18n_resources.go
) is not present in the correct package.Note: This issue ONLY occurs if the
--init-code-snippet-filename
is NOT providedThis PR will handle the binary file generation for the user by generating the file and storing in the correct package.
Callouts
cf
folder when searching for localization fileSteps to Test
Setup
test
)go.mod
:go mod init example.com/test
i18n
i18n
folder in step 3extract-strings
command to extract the strings and generated localization file (demo1.go.en.json
):-
i18n4go extract-strings -d ./ -r -o i18n/resources --exclude i18n/excluded.json
i18n4go merge-strings -d i18n/resources -s en
Replicate Issue
i18n4go rewrite-package --verbose --directory ./ --i18n-strings-filename i18n/resources/en.all.json
i18n_init.go
file is generatedi18n_init.go
file and verify that thegithub.com/maximilien/i18n4go/i18n
package fails to importinit.go
file or open the file directly located../../go/../pkg/mod/github.com/maximilien/[email protected]/i18n/init.go
undefined: resources
appears on line 117Resolution
i18n_init.go
filego mod edit -replace github.com/maximilien/i18n4go=/root/path/to/i18n4go/source/code
go mod tidy
i18n4go rewrite-package --verbose --directory ./ --i18n-strings-filename i18n/resources/en.all.json
i18n_resources.go
file has been generateddemo1.go
:go build -o demo
./demo
Resolves: #127