From b2215db6873126b295fff23333b4558e40e0965d Mon Sep 17 00:00:00 2001 From: Anchor Date: Tue, 11 Nov 2014 14:00:36 -0800 Subject: [PATCH] Fix grammar and sentence structure --- en/eBook/10.2.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/en/eBook/10.2.md b/en/eBook/10.2.md index d68eea8e..5c78fe74 100644 --- a/en/eBook/10.2.md +++ b/en/eBook/10.2.md @@ -4,7 +4,7 @@ The previous section described how to set locales. After the locale has been set ## Localized textual content -Plain text is the most common way of representing information in web applications, and the bulk of your localized content will likely take this form. The goal is to provide textual content that is both idiomatic to regional expressions and feels natural for foreign users of your site. One solution is to create a nested map of locales, native language strings and their international counterparts. When clients request pages with some textual content, we first check their desired locale, then retrieve the corresponding strings from the appropriate map. The following snippet is a simple example of this process: +Plain text is the most common way of representing information in web applications, and the bulk of your localized content will likely take this form. The goal is to provide textual content that is both idiomatic to regional expressions and feels natural for foreign users of your site. One solution is to create a nested map of locales, native language strings and their local counterparts. When clients request pages with some textual content, we first check their desired locale, then retrieve the corresponding strings from the appropriate map. The following snippet is a simple example of this process: package main @@ -38,24 +38,23 @@ Plain text is the most common way of representing information in web application The above example sets up maps of translated strings for different locales (in this case, the Chinese and English locales). We map our `cn` translations to the same English language keys so that we can reconstruct our English text message in Chinese. If we wanted to switch our text to any other locale we may have implemented, it'd be a simple matter of setting one `lang` variable. -Simple key-value substitutions can sometimes be inadequate for our needs. For example, "I am 30 years old", Chinese expression "I am 30 years old," and where 30 is a variable, how to do it? This time, we can combine `fmt.Printf` function to achieve, see the following code: +Simple key-value substitutions can sometimes be inadequate for our needs. For example, if we had a phrase such as "I am 30 years old" where 30 is a variable, how would we localize it? In cases like these, we can combine use the `fmt.Printf` function to achieve the desired result: en["how old"] = "I am %d years old" cn["how old"] = "我今年%d岁了" fmt.Printf(msg(lang, "how old"), 30) -The above example code is only to demonstrate the internal implementations, but the actual data is stored in the JSON inside, so we can `json.Unmarshal` to populate the data for the corresponding map. +The example code above is only for the purpose of demonstration; actual locale data is typically stored in JSON format in our database, allowing us to execute a simple `json.Unmarshal` to populate map locales with our string translations. ## Localized date and time -Because the relationship between time zones, the same time, in different regions, which means that is not the same, but because of the relationship between Locale and time formats are not the same, for example, Chinese environment may be displayed: -`October 24, 2012 Wednesday 23:11 minutes and 13 seconds CST`, while in the English environment may show: `Wed Oct 24 23:11:13 CST 2012`. That which we need to address two points: +Because of our time zone conventions, the time in one region of the world can be different than the time in another region. Similarly, the way in which time is represented can also vary from locale to locale. For example, a Chinese environment may read `2012年10月24日 星期三 23时11分13秒 CST`, while in English, it might be: `Wed Oct 24 23:11:13 CST 2012`. Not only are there variations in language, but there are differences in formatting also. So, when it comes to localizing dates and times, we need to address the following two points: 1. time zones 2. formatting issues -`$GOROOT/lib/time/package/timeinfo.zip` contain locale corresponds to the time zone definition, in order to obtain a time corresponding to the current locale, we should first use `time.LoadLocation (name string)` Get the region corresponding to the locale, such as `Asia/Shanghai` or `America/Chicago` corresponding to the time zone information, and then use this information to call the `time.Now` time object obtained collaborate to get the final time. Detailed Look at the following example (this example uses the example above, some of the variables): +The `$GOROOT/lib/time/package/timeinfo.zip` directory contains locales corresponding to time zone definitions. In order to obtain the time corresponding to a user's current locale, we should first use `time.LoadLocation(name string)` to get a Location object corresponding to our locale, passing in a string representing the locale such as `Asia/Shanghai` or `America/Chicago`. We can then use this Location object in conjunction with a Time object (obtained by calling `time.Now`) to get the final time using the Time object's `In` method. A detailed look at this process can be seen below (this example uses some of the variables from the example above): en["time_zone"] = "America/Chicago" cn["time_zone"] = "Asia/Shanghai" @@ -65,17 +64,17 @@ Because the relationship between time zones, the same time, in different regions t = t.In(loc) fmt.Println(t.Format(time.RFC3339)) -We can handle text format similar way to solve the problem of time format, for example as follows: +We can handle text formatting in a similar way to solve our time formatting problem: en["date_format"]="%Y-%m-%d %H:%M:%S" cn["date_format"]="%Y年%m月%d日 %H时%M分%S秒" fmt.Println(date(msg(lang,"date_format"),t)) - func date(fomate string,t time.Time) string{ + func date(fomat string, t time.Time) string{ year, month, day = t.Date() hour, min, sec = t.Clock() - //Parsing the corresponding %Y%m%d%H%M%S and then return information + //Parsing the corresponding %Y%m%d%H%M%S and then returning the information //%Y replaced by 2012 //%m replaced by 10 //%d replaced by 24