Search code examples
javascriptlocaledate-fns

datefns ru locale incorrect short month name


I found that all short month name in en or de locale don't have any sign at the end but in ru locale there are (like 'янв.'). But it's kinda weird cause they are at the end of some of months but not of all ('янв.' but 'июнь'). Is there is any options in format function in date-fns to hide that dots?

I found this locale file https://github.com/date-fns/date-fns/blob/main/src/locale/ru/snapshot.md and I suppose it's incorrect translation. May be there is any options to override this file?


Solution

  • I came up with a solution like this

        const monthsShortNames: string[] = ['янв', 'фев', 'март', 'апр', 'май', 'июнь', 'июль', 'авг', 'сент', 'окт', 'нояб', 'дек'];
    export const customRuLocale: Locale = {
      ...ru,
      localize: {
        ...ru.localize,
        month: (value, options): string=> {
          if(options?.context==='standalone'&& options?.width==='abbreviated'){
            return monthsShortNames[value] || '';
          }else {
            return ru.localize.month(value, options);
          }
        }
      },
    };
    

    so I overrided ru locale with new months names