~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/chai2010/gettext-go/gettext/local.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
2
 
// Use of this source code is governed by a BSD-style
3
 
// license that can be found in the LICENSE file.
4
 
 
5
 
package gettext
6
 
 
7
 
import (
8
 
        "os"
9
 
        "strings"
10
 
)
11
 
 
12
 
func getDefaultLocale() string {
13
 
        if v := os.Getenv("LC_MESSAGES"); v != "" {
14
 
                return simplifiedLocale(v)
15
 
        }
16
 
        if v := os.Getenv("LANG"); v != "" {
17
 
                return simplifiedLocale(v)
18
 
        }
19
 
        return "default"
20
 
}
21
 
 
22
 
func simplifiedLocale(lang string) string {
23
 
        // en_US/en_US.UTF-8/zh_CN/zh_TW/el_GR@euro/...
24
 
        if idx := strings.Index(lang, ":"); idx != -1 {
25
 
                lang = lang[:idx]
26
 
        }
27
 
        if idx := strings.Index(lang, "@"); idx != -1 {
28
 
                lang = lang[:idx]
29
 
        }
30
 
        if idx := strings.Index(lang, "."); idx != -1 {
31
 
                lang = lang[:idx]
32
 
        }
33
 
        return strings.TrimSpace(lang)
34
 
}