i18n

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 7 Imported by: 0

README ΒΆ

I18n

Quick Start

We provide multiple automated build methods, choose any of the following:

Method 1: Using Shell Script (Linux/macOS)
# Execute complete build
./scripts/build_i18n.sh

# Clean files
./scripts/build_i18n.sh clean

# Show help
./scripts/build_i18n.sh help
Method 2: Using PowerShell Script (Windows)
# Execute complete build
.\scripts\build_i18n.ps1

# Clean files
.\scripts\build_i18n.ps1 -Clean

# Show help
.\scripts\build_i18n.ps1 -Help
Method 3: Using Command Tool
# Execute complete build
go run cmd/make/main.go -generate-json

# Clean files
go run cmd/make/main.go -clean

# Show version
go run cmd/make/main.go -version
Method 4: Using Makefile (requires make command)
# Execute complete build
make -f scripts/Makefile.i18n all

# Or execute individual steps
make -f scripts/Makefile.i18n download-iana
make -f scripts/Makefile.i18n download-timezonedb
make -f scripts/Makefile.i18n download-cldr
make -f scripts/Makefile.i18n download-windows
make -f scripts/Makefile.i18n generate-json

# Clean files
make -f scripts/Makefile.i18n clean

# Show help
make -f scripts/Makefile.i18n help

πŸ“‹ Manual Build Steps (Deprecated)

⚠️ Note: The following steps are manual build method and not recommended. Please prioritize using the automated scripts above.

1. Get tzdata from https://data.iana.org
1.1 Download tzdata from https://data.iana.org
mkdir tzdb
cd tzdb
wget https://www.iana.org/time-zones/repository/tzcode-latest.tar.gz
wget https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz
gzip -dc tzcode-latest.tar.gz | tar -xf -
gzip -dc tzdata-latest.tar.gz | tar -xf -
1.2 Download tzdata from https://timezonedb.com
wget https://timezonedb.com/files/TimeZoneDB.csv.zip -O TimeZoneDB.csv.zip
zip -d TimeZoneDB.csv.zip
1.3 Download ldmlSupplemental.dtd from https://github.com/unicode-org/cldr/blob/main/common/dtd/ldmlSupplemental.dtd
1.4 Download windowsZones.xml from https://github.com/unicode-org/cldr/blob/main/common/supplemental/windowsZones.xml

πŸ› οΈ Automated Script Features

βœ… Implemented Features
  • Automatic Download: Download timezone data from multiple sources
  • Retry Mechanism: Automatic retry on network failures
  • Error Handling: Detailed error messages and logging
  • Cross-platform: Support for Linux, macOS, and Windows
  • Cleanup Function: One-click cleanup of all generated files
  • Dependency Check: Automatic checking of required command-line tools
πŸ“ Generated File Structure
toolkits/i18n/
β”œβ”€β”€ tzdb/                    # IANA timezone data source
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ country.csv          # Country data
β”‚   └── time_zone.csv        # Timezone data
β”œβ”€β”€ windows/
β”‚   β”œβ”€β”€ ldmlSupplemental.dtd # CLDR DTD file
β”‚   β”œβ”€β”€ windowsZones.xml     # Windows timezone mapping
β”‚   └── windows_zones.json   # Converted JSON
β”œβ”€β”€ tz/
β”‚   β”œβ”€β”€ country.json         # Country data JSON
β”‚   └── time_zone.json       # Timezone data JSON
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ build_i18n.sh        # Linux/macOS build script
β”‚   β”œβ”€β”€ build_i18n.ps1       # Windows PowerShell script
β”‚   └── Makefile.i18n        # Make build file
└── cmd/make/
    β”œβ”€β”€ main.go              # Command-line tool
    └── go.mod               # Go module file

πŸ”§ Dependency Requirements

Required Tools
  • wget or curl (for downloading files)
  • tar (for extracting .tar.gz files)
  • gzip (for extraction)
  • unzip (for extracting .zip files)
  • go (for generating JSON files)
Optional Tools
  • 7z (alternative to tar and unzip on Windows)
  • make (for Makefile build)

🚨 Troubleshooting

Common Issues
  1. Network Connection Issues

    # Check network connection
    ping www.iana.org
    ping timezonedb.com
    
  2. Permission Issues

    # Linux/macOS
    chmod +x scripts/build_i18n.sh
    
    # Windows (PowerShell administrator mode)
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    
  3. Missing Dependencies

    # Ubuntu/Debian
    sudo apt-get install wget tar gzip unzip golang-go
    
    # macOS
    brew install wget golang
    
    # Windows (using Chocolatey)
    choco install wget golang
    

πŸ“ Contributing

If you find issues with the automated scripts or have improvement suggestions, please submit an Issue or Pull Request.

Documentation ΒΆ

Overview ΒΆ

Package i18n implements the functions, types, and interfaces for the module.

Package i18n implements the functions, types, and interfaces for the module.

Package i18n implements the functions, types, and interfaces for the module.

Package i18n implements the functions, types, and interfaces for the module.

Package i18n implements the functions, types, and interfaces for the module.

Package i18n implements the functions, types, and interfaces for the module.

Package i18n implements the functions, types, and interfaces for the module.

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var (
	// Locales is the current system language settings
	Locales = locale.Languages()
	// DefaultLocale is the default system language settings
	DefaultLocale = Make(defaultLocaleString)
	Languages     = []Tag{
		language.Afrikaans,
		language.Amharic,
		language.Arabic,
		language.ModernStandardArabic,
		language.Azerbaijani,
		language.Bulgarian,
		language.Bengali,
		language.Catalan,
		language.Czech,
		language.Danish,
		language.German,
		language.Greek,
		language.English,
		language.AmericanEnglish,
		language.BritishEnglish,
		language.Spanish,
		language.EuropeanSpanish,
		language.LatinAmericanSpanish,
		language.Estonian,
		language.Persian,
		language.Finnish,
		language.Filipino,
		language.French,
		language.CanadianFrench,
		language.Gujarati,
		language.Hebrew,
		language.Hindi,
		language.Croatian,
		language.Hungarian,
		language.Armenian,
		language.Indonesian,
		language.Icelandic,
		language.Italian,
		language.Japanese,
		language.Georgian,
		language.Kazakh,
		language.Khmer,
		language.Kannada,
		language.Korean,
		language.Kirghiz,
		language.Lao,
		language.Lithuanian,
		language.Latvian,
		language.Macedonian,
		language.Malayalam,
		language.Mongolian,
		language.Marathi,
		language.Malay,
		language.Burmese,
		language.Nepali,
		language.Dutch,
		language.Norwegian,
		language.Punjabi,
		language.Polish,
		language.Portuguese,
		language.BrazilianPortuguese,
		language.EuropeanPortuguese,
		language.Romanian,
		language.Russian,
		language.Sinhala,
		language.Slovak,
		language.Slovenian,
		language.Albanian,
		language.Serbian,
		language.SerbianLatin,
		language.Swedish,
		language.Swahili,
		language.Tamil,
		language.Telugu,
		language.Thai,
		language.Turkish,
		language.Ukrainian,
		language.Urdu,
		language.Uzbek,
		language.Vietnamese,
		language.Chinese,
		language.SimplifiedChinese,
		language.TraditionalChinese,
		language.Zulu,
	}
)

Functions ΒΆ

func Compare ΒΆ

func Compare(lt, rt Tag) int

Compare compares two language tags and returns 1 if they match, 0 otherwise.

func CountryStrings ΒΆ

func CountryStrings() []string

CountryStrings returns a list of country strings based on the supported languages.

func FromRequest ΒΆ

func FromRequest(req *http.Request) []language.Tag

FromRequest retrieves the Tag information from the HTTP request. req: The HTTP request from which to retrieve the Tag information. Returns a slice of Tag parsed from the "Accept-Language" header of the request.

func LanguageStrings ΒΆ

func LanguageStrings() []string

LanguageStrings returns a list of language strings for all languages in the Languages slice.

func Make ΒΆ

func Make(lang string) language.Tag

func Parse ΒΆ

func Parse(tag string) (language.Tag, error)

func ParseAcceptLanguage ΒΆ

func ParseAcceptLanguage(acceptLanguage string) []language.Tag

ParseAcceptLanguage parses the "Accept-Language" header to obtain a slice of language.Tag. acceptLanguage: The value of the "Accept-Language" header. Returns a slice of language.Tag, or a slice containing only the default locale if parsing fails or the result is empty.

func PreferredLocale ΒΆ

func PreferredLocale(acceptLanguage string) string

PreferredLocale gets the current system language settings multi-language are supported, the first match is returned if no match is found, the default system language settings is returned

func WithTags ΒΆ

func WithTags(ctx context.Context, tags ...Tag) context.Context

WithTags creates a new context with Tag information. ctx: The parent context. tags: The Tag information to be included in the context. Returns a new context containing the Tag information.

Types ΒΆ

type LocaleCode ΒΆ

type LocaleCode struct {
	Locale          string `json:"Locale"`
	LanguageCode    string `json:"Language code"`
	LCIDString      string `json:"LCID string"`
	LCIDDecimal     int    `json:"LCID Decimal"`
	LCIDHexadecimal int    `json:"LCID Hexadecimal"`
	Codepage        int    `json:"Codepage"`
}

type Tag ΒΆ

type Tag = language.Tag

func Country2Language ΒΆ

func Country2Language(lang Tag) Tag

Country2Language converts a country tag to a language tag.

func CountryLanguage ΒΆ

func CountryLanguage(lang Tag) Tag

CountryLanguage converts a country tag to a language tag with region.

func FromTag ΒΆ

func FromTag(ctx context.Context) Tag

FromTag retrieves the first Tag from the context. ctx: The context from which to retrieve the Tag information. Returns the first Tag, or the default locale if no Tag information is found or the slice is empty.

func FromTags ΒΆ

func FromTags(ctx context.Context) []Tag

FromTags retrieves the Tag information from the context. ctx: The context from which to retrieve the Tag information. Returns a slice of Tag, or a slice containing only the default locale if no Tag information is found.

func Language2Country ΒΆ

func Language2Country(lang Tag) Tag

Language2Country converts a language tag to a country tag.

func String2Country ΒΆ

func String2Country(localeString string) Tag

String2Country converts a locale string to a country tag.

func String2Language ΒΆ

func String2Language(localeString string) Tag

String2Language converts a locale string to a language tag.

func Unknown2Country ΒΆ

func Unknown2Country(lang Tag) Tag

Unknown2Country converts an unknown language tag to a country tag.

func Unknown2Language ΒΆ

func Unknown2Language(lang Tag) Tag

Unknown2Language converts an unknown language tag to a language tag.

Directories ΒΆ

Path Synopsis
cmd
make command
Package main implements the I18n data generation command.
Package main implements the I18n data generation command.
Package tz implements the functions, types, and interfaces for the module.
Package tz implements the functions, types, and interfaces for the module.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL