Expanding monday to add some extra locales.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Evan Tann facb282572
Some checks failed
Go / Build (push) Has been cancelled
change go module to evantann.com host
2026-09-22 09:20:27 +01:00
.github/workflows fix actions config 2025-06-18 12:41:14 +04:00
.gitignore Update .gitignore to manage IdeaProject + go module managament 2020-01-30 09:31:30 +01:00
automation.go Update detectLocale method to skip word with less than 2 characters 2023-08-27 22:24:56 +02:00
automation_test.go Update detectLocale method to skip word with less than 2 characters 2023-08-27 22:24:56 +02:00
default_formats.go add mt_MT localization 2026-09-22 09:15:36 +01:00
default_orders.go order output for GetShortDays/GetShortMonths/GetLongMonths/GetLongDays 2019-12-11 15:27:48 +01:00
doc.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_bg_bg.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_ca_es.go Add locale ca_ES 2015-12-07 18:11:38 +00:00
format_common.go adding support for et-EE 2021-08-03 14:30:50 +02:00
format_cs_cz.go Adding cs_CZ locale (Fix) 2017-02-08 23:25:05 +01:00
format_da_dk.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_de_de.go de_DE: Fix short forms 2025-06-16 01:14:06 +02:00
format_el_gr.go Greek locale + bug fixes 2015-05-23 21:02:29 +03:00
format_en_gb.go add locale EnGB as copy from EnUS for different week day order 2019-12-12 09:46:51 +01:00
format_en_us.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_es_es.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_et_ee.go adding support for et-EE 2021-08-03 14:30:50 +02:00
format_fi_fi.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_fr_fr.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_ga_ie.go add ga_IE localization 2026-09-22 09:14:58 +01:00
format_hr_hr.go Add hr-HR support 2021-08-03 15:11:07 +02:00
format_hu_hu.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_id_id.go fix: updated August short month name for id_ID locale 2023-08-25 21:43:38 +07:00
format_it_it.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_ja_jp.go Add Korean Support 2019-12-07 21:22:42 +09:00
format_kk_kz.go kazakh locale added 2023-06-19 10:21:31 +05:00
format_ko_kr.go Add Korean Support 2019-12-07 21:22:42 +09:00
format_lt_lt.go Add support for lt_LT: Lithuanian (Lithuania) 2021-01-07 10:08:41 +02:00
format_lv_lv.go Add lv-LV support 2021-08-03 16:53:52 +02:00
format_mt_mt.go add mt_MT localization 2026-09-22 09:15:36 +01:00
format_nb_no.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_nl_be.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_nn_no.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_pl_pl.go Fix Polish support 2023-12-15 23:16:31 +01:00
format_pt_br.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_pt_pt.go Go fmt all the things 2015-02-05 14:28:28 +00:00
format_ro_RO.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_ru_ru.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_sk_sk.go Add sk-SK support 2021-08-03 17:28:27 +02:00
format_sl_si.go Add support for slovenian language (sl_SI) 2019-02-14 16:07:57 +01:00
format_sv_se.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_th_th.go Add support for thai language (th_TH) 2022-07-08 13:11:06 +07:00
format_tr_tr.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00
format_uk_ua.go Update format_uk_ua.go 2021-01-04 22:52:19 +02:00
format_uz_uz.go Add uzbek uz_UZ 2022-07-09 22:55:12 +05:00
format_zh_cn.go Make date formats work with Japanese 2015-01-27 01:14:13 +00:00
format_zh_hk.go Added Chinese (Mainland, Taiwan & Hong Kong) 2013-04-27 10:13:12 +08:00
format_zh_tw.go Added Chinese (Mainland, Taiwan & Hong Kong) 2013-04-27 10:13:12 +08:00
go.mod change go module to evantann.com host 2026-09-22 09:20:27 +01:00
LICENSE fixed license #47 2021-07-23 22:44:47 +02:00
locale.go add mt_MT localization 2026-09-22 09:15:36 +01:00
monday.go add mt_MT localization 2026-09-22 09:15:36 +01:00
monday_test.go add mt_MT localization 2026-09-22 09:15:36 +01:00
README.md change go module to evantann.com host 2026-09-22 09:20:27 +01:00
set.go Remove dependency of package fatih/set 2018-07-12 09:55:16 +02:00
set_test.go Remove dependency of package fatih/set 2018-07-12 09:55:16 +02:00
utils_layout.go Improve monday.Format() performance using StringBuilder 2019-07-06 09:50:59 -04:00
utils_layout_test.go Added Bulgarian + gofmt. 2013-04-26 23:47:35 +04:00

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.

Go

Installing

go get evantann.com/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)
    LocaleUkUA = "uk_UA" // Ukrainian (Ukraine)
    LocaleBgBG = "bg_BG" // Bulgarian (Bulgaria)
    LocaleZhCN = "zh_CN" // Chinese (Mainland)
    LocaleZhTW = "zh_TW" // Chinese (Taiwan)
    LocaleZhHK = "zh_HK" // Chinese (Hong Kong)
    LocaleKoKR = "ko_KR" // Korean (Korea)
    LocaleJaJP = "ja_JP" // Japanese (Japan)
    LocaleElGR = "el_GR" // Greek (Greece)
    LocaleIdID = "id_ID" // Indonesian (Indonesia)
    LocaleFrGP = "fr_GP" // French (Guadeloupe)
    LocaleFrLU = "fr_LU" // French (Luxembourg)
    LocaleFrMQ = "fr_MQ" // French (Martinique)
    LocaleFrGF = "fr_GF" // French (French Guiana)
    LocaleFrGF = "fr_RE" // French (Reunion)
    LocaleCsCZ = "cs_CZ" // Czech (Czech Republic)
    LocaleSlSI = "sl_SI" // Slovenian (Slovenia)
    LocaleLtLT = "lt_LT" // Lithuanian (Lithuania)
    LocaleEtEE = "et_EE" // Estonian (Estonia)
    LocaleHrHR = "hr_HR" // Croatian (Croatia)
    LocaleLvLV = "lv_LV" // Latvian (Latvia)
    LocaleSkSK = "sk_SK" // Slovak (Slovakia)
    LocaleThTH = "th_TH" // Thai (Thailand)
    LocaleUzUZ = "uz_UZ" // Uzbek (Uzbekistan)
    LocaleKkKZ = "kk_KZ" // Kazakh (Kazakhstan)
    LocaleGaIe = "ga_IE" // Irish (Ireland)
    LocaleMtMt = "mt_MT" // Maltese (Malta)
)

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