Merge commit '091c22dea949dfab3fd474d188ef9d6368758ab2' into ja
This commit is contained in:
@@ -82,21 +82,21 @@ We can handle text formatting in a similar way to solve our time formatting prob
|
||||
|
||||
## Localized currency value
|
||||
|
||||
Various regions of the currency is not the same, is also treated with a date about the details see the following code:
|
||||
Obviously, currency differs from region to region also. We can treat it the same way we treated our dates:
|
||||
|
||||
en["money"] ="USD %d"
|
||||
cn["money"] ="¥%d元"
|
||||
|
||||
fmt.Println(date(msg(lang,"date_format"),100))
|
||||
|
||||
func money_format(fomate string,money int64) string{
|
||||
return fmt.Sprintf(fomate,money)
|
||||
func money_format(fomat string, money int64) string{
|
||||
return fmt.Sprintf(fomat, money)
|
||||
}
|
||||
|
||||
|
||||
## Localization views and resources
|
||||
## Localization of views and resources
|
||||
|
||||
We may use Locale to show different views that contain different images, css, js and other static resources. So how to deal with these information? First we shall locale to organize file information, see the following file directory Arrangement:
|
||||
We can serve customized views with different images, css, js and other static resources depending on the current locale. One way to accomplish this is by organizing these files into their respective locales. Here's an example:
|
||||
|
||||
views
|
||||
|--en //English Templates
|
||||
@@ -112,13 +112,13 @@ We may use Locale to show different views that contain different images, css, js
|
||||
index.tpl
|
||||
login.tpl
|
||||
|
||||
With this directory structure we can render to realize where this code:
|
||||
With this directory structure, we can render locale-specific views like so:
|
||||
|
||||
s1, _ := template.ParseFiles("views" + lang + "index.tpl")
|
||||
VV.Lang = lang
|
||||
s1.Execute(os.Stdout, VV)
|
||||
|
||||
As for the inside of the resources inside the index.tpl set as follows:
|
||||
The resources referenced in the `index.tpl` file can be dealt with as follows:
|
||||
|
||||
// js file
|
||||
<script type="text/javascript" src="views/{{.VV.Lang}}/js/jquery/jquery-1.8.0.min.js"></script>
|
||||
@@ -127,11 +127,11 @@ As for the inside of the resources inside the index.tpl set as follows:
|
||||
// Picture files
|
||||
<img src="views/{{.VV.Lang}}/images/btn.png">
|
||||
|
||||
With this view, and the way to localize the resources, we can easily be expanded.
|
||||
With dynamic views and the way we've localized our resources, we will be able to add more locales without much effort.
|
||||
|
||||
## Summary
|
||||
|
||||
This section describes how to use and store local resources, sometimes through the conversion function to achieve, sometimes through lang to set up, but eventually through key-value way to store Locale corresponding data when needed remove the corresponding Locale information, if it is a text message directly to the output, if it is the date and time or money, you need to pass `fmt.Printf` or other formatting function to deal with, and for different views and resources Locale is the most simple, as long as increase in the path which can be achieved lang.
|
||||
This section described how to use and store local resources. We learned that we can use conversion functions and string interpolation for this, and saw that maps can be an effective way of storing locale-specific data. For the latter, we could simply extract the corresponding locale information when needed -if it was textual content we desired, our mapped translations and idioms could be piped directly to the output. If it was something more sophisticated like time or currency, we simply used the `fmt.Printf` function to format it before-hand. Localizing our views and resources was the easiest case, and simply involved organizing our files into their respective locales, then referencing them from their locale relative paths.
|
||||
|
||||
## Links
|
||||
|
||||
|
||||
Reference in New Issue
Block a user