datesi18n

package module
v0.0.4-beta Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 3 Imported by: 1

README

DatesI18n

A library to do quick translations of Day and Month names, including 'short' names, where provided.

Usage

package main

import (
  "fmt"

  datesI18N "github.com/davidgs/datesI18N"
)

func main() {
  fr := datesI18N.NewDatesI18N("fr") // french
  wed := fr.Weekdays.Wednesday
  fmt.Println("French Wednesday: ", wed)
}

Output:

French Wednesday: Mercredi

If you are using the Go time Package, you can use this package to give you translated Days and months.

Language Support

Note: Not all languages have all parts translated! Soo the lang/ directory for languages supported. See the individual .json file for which parts of the Days/Months are provided.

If you would like to provide additional translations or additions to a given translation, please submit a PR!

See Supported Languages for a current list of fully- or partially-supported languages

Documentation

Overview

Package datesi18n provides internationalization for programs needing language support for weekdays and months. The package is intended to be used with the dates package.

The following code is an example of using the datesi18n package:

import "github.com/mjibson/go-datesi18n"

func main() {
	d := datesi18n.NewDatesI18N("en")
	fmt.Println(d.Weekdays.Monday)
	fmt.Println(d.WeekdaysShort.Monday)
	fmt.Println(d.WeekdaysMin.Monday)
	fmt.Println(d.Months.January)
}

The output of the program is:

Monday
Mon
M
January

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatesI18N

type DatesI18N struct {
	Weekdays      DatesWeekdays      `json:"weekdays"`
	WeekdaysShort DatesWeekdaysShort `json:"weekdaysshort"`
	WeekdaysMin   DatesWeekdaysMin   `json:"weekdaysmin"`
	Months        DatesMonths        `json:"months"`
	MonthsShort   DatesMonthsShort   `json:"monthsshort"`
	Language      string             `json:"language"`
}

DatesI18N is a struct that holds the internationalization data for the dates package.

func NewDatesI18N

func NewDatesI18N(lang string) *DatesI18N

NewDatesI18N returns a new DatesI18N struct initialized with the language values for the given language

func (*DatesI18N) DayName

func (d *DatesI18N) DayName(day int) string

DayName returns the name of the day of the week given by index number.

func (*DatesI18N) DayNumber

func (d *DatesI18N) DayNumber(day string) int

DayNumber returns the number of the day of the week given by name.

func (*DatesI18N) MinDayName

func (d *DatesI18N) MinDayName(day int) string

MinDayName returns the minimal name of the day of the week given by index number.

func (*DatesI18N) MinDayNumber

func (d *DatesI18N) MinDayNumber(day string) int

MinDayNumber returns the number of the day of the week given by minimal name.

func (*DatesI18N) MonthName

func (d *DatesI18N) MonthName(month int) string

MonthName returns the name of the month given by index number.

func (*DatesI18N) MonthNumber

func (d *DatesI18N) MonthNumber(month string) int

MonthNumber returns the number of the month given by name.

func (*DatesI18N) ShortDayName

func (d *DatesI18N) ShortDayName(day int) string

ShortDayName returns the short name of the day of the week given by index number.

func (*DatesI18N) ShortDayNumber

func (d *DatesI18N) ShortDayNumber(day string) int

ShortDayNumber returns the number of the day of the week given by short name.

func (*DatesI18N) ShortMonthName

func (d *DatesI18N) ShortMonthName(month int) string

ShortMonthName returns the short name of the month given by index number.

func (*DatesI18N) ShortMonthNumber

func (d *DatesI18N) ShortMonthNumber(month string) int

ShortMonthNumber returns the number of the month given by short name.

type DatesMonths

type DatesMonths struct {
	January   string `json:"january"`
	February  string `json:"february"`
	March     string `json:"march"`
	April     string `json:"april"`
	May       string `json:"may"`
	June      string `json:"june"`
	July      string `json:"july"`
	August    string `json:"august"`
	September string `json:"september"`
	October   string `json:"october"`
	November  string `json:"november"`
	December  string `json:"december"`
}

DatesMonths is a struct that holds the names of the months.

type DatesMonthsShort

type DatesMonthsShort struct {
	January   string `json:"jan"`
	February  string `json:"feb"`
	March     string `json:"mar"`
	April     string `json:"apr"`
	May       string `json:"may"`
	June      string `json:"jun"`
	July      string `json:"jul"`
	August    string `json:"aug"`
	September string `json:"sep"`
	October   string `json:"oct"`
	November  string `json:"nov"`
	December  string `json:"dec"`
}

DatesMonthsShort is a struct that holds the short names of the months.

type DatesWeekdays

type DatesWeekdays struct {
	Sunday    string `json:"sunday"`
	Monday    string `json:"monday"`
	Tuesday   string `json:"tuesday"`
	Wednesday string `json:"wednesday"`
	Thursday  string `json:"thursday"`
	Friday    string `json:"friday"`
	Saturday  string `json:"saturday"`
}

DatesWeekdays is a struct that holds the names of the weekdays.

type DatesWeekdaysMin

type DatesWeekdaysMin struct {
	Sunday    string `json:"Su"`
	Monday    string `json:"Mo"`
	Tuesday   string `json:"Tu"`
	Wednesday string `json:"We"`
	Thursday  string `json:"Th"`
	Friday    string `json:"Fr"`
	Saturday  string `json:"Sa"`
}

DattesWeekdaysMin is a struct that holds the minimal names of the weekdays.

type DatesWeekdaysShort

type DatesWeekdaysShort struct {
	Sunday    string `json:"sun"`
	Monday    string `json:"mon"`
	Tuesday   string `json:"tue"`
	Wednesday string `json:"wed"`
	Thursday  string `json:"thu"`
	Friday    string `json:"fri"`
	Saturday  string `json:"sat"`
}

DatesWeekdaysShort is a struct that holds the short names of the weekdays.

Jump to

Keyboard shortcuts

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