Skip to content
forked from goodsign/monday

Monday is a minimalistic translator for month and day of week names in time.Date objects.

License

Notifications You must be signed in to change notification settings

hailocab/monday

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

Monday is a minimalistic translator for month and day of week names in time.Date objects. Supports 20+ different locales. Written in pure Go.

Installing

go get github.com/goodsign/monday

Usage

Format

Given that you already use time.Format somewhere in your code, to translate your output you should import monday and replace

  yourTime.Format(yourLayout)

with

  // Change LocaleEnUS to the locale you want to use for translation
  monday.Format(yourTime, yourLayout, monday.LocaleEnUS) 

Parse

Given that you already use time.ParseInLocation somewhere in your code, to parse input string in a different language you should import monday and replace

  time.ParseInLocation(yourLayout, yourString, yourLocation)

with

  // Change LocaleEnUS to the locale you want to use for translation
  monday.ParseInLocation(yourLayout, yourString, yourLocation, monday.LocaleEnUS) 

Predefined formats

Monday declares some predefined formats: Full, Long, Medium, Short, DateTime formats for each locale. E.g. to get short format for any locale you can use map:

monday.ShortFormatsByLocale[locale]

Usage notes

Monday is not an alternative to standard time package. It is a temporary solution to use while the internationalization features are not ready.

That's why monday doesn't create any additional parsing algorithms, layout identifiers. It is just a wrapper for time.Format and time.ParseInLocation and uses all the same layout IDs, constants, etc.

So, the changes you need to temporarily switch to monday (while the internationalization features are being developed) are minimal: you preserve your layout, your time object, your parsed date string formats and the only change is the func call itself.

Locales

Supported locales are listed in locale.go file.

const (
    LocaleEnUS = "en_US"    // English (United States)
    LocaleEnGB = "en_GB"    // English (United Kingdom)
    LocaleDaDK = "da_DK"    // Danish (Denmark)
    LocaleNlBE = "nl_BE"    // Dutch (Belgium)
    LocaleNlNL = "nl_NL"    // Dutch (Netherlands)
    LocaleFiFI = "fi_FI"    // Finnish (Finland)
    LocaleFrFR = "fr_FR"    // French (France)
    LocaleFrCA = "fr_CA"    // French (Canada)
    LocaleDeDE = "de_DE"    // German (Germany)
    LocaleHuHU = "hu_HU"    // Hungarian (Hungary)
    LocaleItIT = "it_IT"    // Italian (Italy)
    LocaleNnNO = "nn_NO"    // Norwegian Nynorsk (Norway)
    LocaleNbNO = "nb_NO"    // Norwegian Bokmål (Norway)
    LocalePlPL = "pl_PL"    // Polish (Poland)
    LocalePtPT = "pt_PT"    // Portuguese (Portugal)
    LocalePtBR = "pt_BR"    // Portuguese (Brazil)
    LocaleRoRO = "ro_RO"    // Romanian (Romania)
    LocaleRuRU = "ru_RU"    // Russian (Russia)
    LocaleEsES = "es_ES"    // Spanish (Spain)
    LocaleEsES = "ca_ES"    // Catalan (Spain)
    LocaleSvSE = "sv_SE"    // Swedish (Sweden)
    LocaleTrTR = "tr_TR"    // Turkish (Turkey)
    LocaleBgBF = "bg_BG"    // Bulgarian (Bulgaria)
    LocaleZhCN = "zh_CN"    // Chinese (Mainland)
    LocaleZhTW = "zh_TW"    // Chinese (Taiwan)
    LocaleZhHK = "zh_HK"    // Chinese (Hong Kong)
)

Thread-safety

Monday initializes all its data once in the init func and then uses only func calls and local vars. Thus, it's thread-safe and doesn't need any mutexes to be used with.

Monday Licence

The Monday library is released under the BSD Licence

LICENCE file

Thanks

About

Monday is a minimalistic translator for month and day of week names in time.Date objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%