Monday is a minimalistic translator for month and day of week names in time.Date objects.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 33 commits behind goodsign:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENCE
README.md
automation.go
automation_test.go
default_formats.go
doc.go
format_bg_bg.go
format_ca_es.go
format_common.go
format_da_dk.go
format_de_de.go
format_el_gr.go
format_en_us.go
format_es_es.go
format_fi_fi.go
format_fr_fr.go
format_hu_hu.go
format_id_id.go
format_it_it.go
format_ja_jp.go
format_nb_no.go
format_nl_be.go
format_nn_no.go
format_pl_pl.go
format_pt_br.go
format_pt_pt.go
format_ro_RO.go
format_ru_ru.go
format_sv_se.go
format_tr_tr.go
format_zh_cn.go
format_zh_hk.go
format_zh_tw.go
locale.go
monday.go
monday_test.go
utils_layout.go
utils_layout_test.go

README.md

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)
    LocaleCaES = "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)
    LocaleJaJP = "ja_JP"    // Japanese (Japan)
    LocaleElGR = "el_GR"    // Greek (Greece)
    LocaleIdID = "id_ID"    // Indonesian (Indonesia)
)

LocaleDetector

    var timeLocaleDetector *monday.LocaleDetector = monday.NewLocaleDetector()
    dateTime, err := timeLocaleDetector.Parse(layout,datestr) 

parses datetime with unknown locale (for now - layout must be defined, as for time.Parse())

useful for text parsing tools/crawlers (f.e.: rss-feeds crawler)

TODO:

  • make LocaleDetector insensitive to whitespaces count

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