This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
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.
During upgrading my old app, I found some i18n features related to the templates were not working correctly. The issues are:
r.HTML(string)
stays with the old format, such asr.HTML("index.html")
, but the template files are forms ofindex.plush.html
andindex.plush.ko-kr.html
(renamed bybuffalo fix
), always the last file is used even though the browser's accept-language has noko
orko-KR
.templateRenderer.updateAliases()
does something unintended.templateRenderer.resolve()
is called twice in many cases since.localizedName()
uses this for checking if there is a template for possible languages.Test environment
templates/index.plush.html
templates/index.plush.ko-kr.html
Debugging result when using
return c.Render(http.StatusOK, r.HTML("index.plush.html"))
--> OK, the correct templates are determined by the direct name match.
For ko-KR:
For the default language:
Debugging result when using
return c.Render(http.StatusOK, r.HTML("index.html"))
--> incorrect file is selected by alias matching.
For ko-KR
For the default language:
Debugging result of the
updateAliases()
: "which aliases are generated?"As shown above, an unnecessary alias
index.ko-kr
is generated for the extensionko-kr
, and theindex.html
andindex.plush
were overwritten by the last template every time and it became the default.The first commit will fix this issue.
For the second issue, the calling time of
resolve()
, the original sequences are as follows:when
ko-KR
is used for the request,The template was evaluated twice. The second commit fixes this issue by introducing a new function
localizedResolve()
. The commit also improves the template-based i18n feature to support short language setting such asko
without the country code part, and also allows developers to create language-only templates such asindex.plush.ko.html
too.