-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(wip): translation module #135
- Loading branch information
Showing
11 changed files
with
439 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"2.0.0-beta.3","build_id":12,"total_build":216} | ||
{"version":"2.0.0-beta.3","build_id":13,"total_build":217} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"2.0.0-beta.3","build_id":12,"total_build":216} | ||
{"version":"2.0.0-beta.3","build_id":13,"total_build":217} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/0xJacky/Nginx-UI/server/internal/translation" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func GetTranslation(c *gin.Context) { | ||
code := c.Param("code") | ||
|
||
c.JSON(http.StatusOK, translation.GetTranslation(code)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package translation | ||
|
||
import ( | ||
"fmt" | ||
"github.com/0xJacky/Nginx-UI/frontend" | ||
"github.com/0xJacky/pofile/pofile" | ||
"io" | ||
"log" | ||
) | ||
|
||
var Dict map[string]pofile.Dict | ||
|
||
func init() { | ||
Dict = make(map[string]pofile.Dict) | ||
|
||
langCode := []string{"zh_CN", "zh_TW", "ru_RU", "fr_FR", "es"} | ||
|
||
for _, v := range langCode { | ||
handlePo(v) | ||
} | ||
} | ||
|
||
func handlePo(langCode string) { | ||
file, err := frontend.DistFS.Open(fmt.Sprintf("src/language/%s/app.po", langCode)) | ||
|
||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
defer file.Close() | ||
|
||
bytes, err := io.ReadAll(file) | ||
|
||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
p, err := pofile.ParseText(string(bytes)) | ||
|
||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
Dict[langCode] = p.ToDict() | ||
} | ||
|
||
func GetTranslation(langCode string) pofile.Dict { | ||
return Dict[langCode] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters