@@ -247,24 +247,28 @@ func ExampleMatcher() {
247
247
// This is the set of tags from which we want to pick the best match. These
248
248
// can be, for example, the supported languages for some package.
249
249
tags := []language.Tag {
250
- language .English ,
251
- language .BritishEnglish ,
252
- language .French ,
253
- language .Afrikaans ,
254
- language .BrazilianPortuguese ,
255
- language .EuropeanPortuguese ,
256
- language .Croatian ,
257
- language .SimplifiedChinese ,
258
- language .Raw .Make ("iw-IL" ),
259
- language .Raw .Make ("iw" ),
260
- language .Raw .Make ("he" ),
250
+ language .English , // en
251
+ language .BritishEnglish , // en-GB
252
+ language .French , // fr
253
+ language .Afrikaans , // af
254
+ language .BrazilianPortuguese , // pt-BR
255
+ language .EuropeanPortuguese , // pt-PT
256
+ language .SimplifiedChinese , // zh-Hans
257
+ language .Raw .Make ("iw-IL" ), // Hebrew from Israel
258
+ language .Raw .Make ("iw" ), // Hebrew
259
+ language .Raw .Make ("he" ), // Hebrew
261
260
}
262
261
m := language .NewMatcher (tags )
263
262
264
263
// A simple match.
265
264
fmt .Println (m .Match (language .Make ("fr" )))
266
265
267
- // Australian English is closer to British than American English.
266
+ // Australian English is closer to British English than American English.
267
+ // The resulting match is "en-GB-u-rg-auzzzz". The first language listed,
268
+ // "en-GB", is the matched language. Next is the region override prefix
269
+ // "-u-rg-", the region override "au", and the region override suffix "zzzz".
270
+ // The region override is for things like currency, dates, and measurement
271
+ // systems.
268
272
fmt .Println (m .Match (language .Make ("en-AU" )))
269
273
270
274
// Default to the first tag passed to the Matcher if there is no match.
@@ -275,15 +279,12 @@ func ExampleMatcher() {
275
279
276
280
fmt .Println ("----" )
277
281
278
- // Someone specifying sr-Latn is probably fine with getting Croatian.
279
- fmt .Println (m .Match (language .Make ("sr-Latn" )))
280
-
281
282
// We match SimplifiedChinese, but with Low confidence.
282
283
fmt .Println (m .Match (language .TraditionalChinese ))
283
284
284
- // Serbian in Latin script is a closer match to Croatian than Traditional
285
- // Chinese to Simplified Chinese.
286
- fmt .Println (m .Match (language .TraditionalChinese , language .Make ("sr-Latn " )))
285
+ // British English is closer to Australian English than Traditional Chinese
286
+ // to Simplified Chinese.
287
+ fmt .Println (m .Match (language .TraditionalChinese , language .Make ("en-AU " )))
287
288
288
289
fmt .Println ("----" )
289
290
@@ -297,7 +298,7 @@ func ExampleMatcher() {
297
298
298
299
fmt .Println ("----" )
299
300
300
- // If a Matcher is initialized with a language and it's deprecated version,
301
+ // If a Matcher is initialized with a language and its deprecated version,
301
302
// it will distinguish between them.
302
303
fmt .Println (m .Match (language .Raw .Make ("iw" )))
303
304
@@ -319,26 +320,23 @@ func ExampleMatcher() {
319
320
320
321
// Output:
321
322
// fr 2 Exact
322
- // en-GB 1 High
323
+ // en-GB-u-rg-auzzzz 1 High
323
324
// en 0 No
324
325
// en 0 No
325
326
// ----
326
- // hr 6 High
327
- // zh-Hans 7 Low
328
- // hr 6 High
327
+ // zh-Hans 6 Low
328
+ // en-GB-u-rg-auzzzz 1 High
329
329
// ----
330
- // pt-BR 4 High
331
- // fr 2 High
332
- // af 3 High
330
+ // pt-BR 4 Exact
331
+ // fr-u-rg-bezzzz 2 High
332
+ // af-u-rg-nazzzz 3 High
333
333
// ----
334
- // iw 9 Exact
335
- // he 10 Exact
334
+ // iw-IL 7 Exact
335
+ // he-u-rg-ilzzzz 9 Exact
336
336
// ----
337
337
// fr-u-cu-frf 2 Exact
338
338
// fr-u-cu-frf 2 High
339
339
// en-u-co-phonebk 0 No
340
-
341
- // TODO: "he" should be "he-u-rg-IL High"
342
340
}
343
341
344
342
func ExampleMatchStrings () {
0 commit comments