forked from toolshed/abra
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			505 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			505 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package lang
 | |
| 
 | |
| import (
 | |
| 	"os"
 | |
| 	"strings"
 | |
| 
 | |
| 	"github.com/leonelquinteros/gotext"
 | |
| )
 | |
| 
 | |
| func GetLocale() string {
 | |
| 	if loc := os.Getenv("LC_MESSAGES"); loc != "" {
 | |
| 		return NormalizeLocale(loc)
 | |
| 	}
 | |
| 
 | |
| 	if loc := os.Getenv("LANG"); loc != "" {
 | |
| 		return NormalizeLocale(loc)
 | |
| 	}
 | |
| 
 | |
| 	return "C.UTF-8"
 | |
| }
 | |
| 
 | |
| func NormalizeLocale(loc string) string {
 | |
| 	if idx := strings.Index(loc, "."); idx != -1 {
 | |
| 		return loc[:idx]
 | |
| 	}
 | |
| 
 | |
| 	if idx := strings.Index(loc, "@"); idx != -1 {
 | |
| 		return loc[:idx]
 | |
| 	}
 | |
| 
 | |
| 	return loc
 | |
| }
 | |
| 
 | |
| var T = gotext.Get
 |