[Localization] %ICUDateTime%MMMM dd, yyyy% months are not returned in English

Hello,

Right now this is my macro:

Schermafbeelding 2021-08-24 om 15.57.08

This is the (Dutch) output when I type ;bu
augustus 24, 2021

I want to have an (English) output like this when I type ;bu
August 24, 2021

How to get an English output when keeping the system language the same?

I also read the wiki, but the only thing I could find is the "Localization" part: token:ICUDateTime [Keyboard Maestro Wiki]

Do you know a solution? Do I need to change this part of the macro to something else? %ICUDateTime%MMMM dd, yyyy%

It shows correctly on my Mac.

Maybe it's due to your system language setting?

Yes, that's right. The system language is Dutch. How to get an English output when keeping the system language (Dutch) the same?

Prior to Mojave, and after Keyboard Maestro 9.0, dates should be in your chosen language. Unfortunately Apple changed Mojave and later to make the system return dates only in the Keyboard Maestro localized language (ie, English), regardless of your chosen locale. Keyboard Maestro 9.0 works around this by claiming to be in all locales, even though it is really only localized for English itself. token:ICUDateTime [Keyboard Maestro Wiki]

Does someone know a workaround? How to get an English output when keeping the system language (Dutch) the same?

If you’re ok with python, this post will help:

import time
import locale

def get_date_in(loc, df):
    formats = ["%d-%b-%Y", "%d %b %Y"]  # Update formats here

    for f in formats:
        if f == df:
            locale.setlocale(locale.LC_ALL, loc)
            loc_date = time.strftime(f)
            return loc_date

demo

french = get_date_in('fr', "%d-%b-%Y")
chinese = get_date_in('zh', "%d %b %Y")
turkish = get_date_in('tr', "%d-%b-%Y")

print(french)
print(chinese)
print(turkish)

12-déc.-2017
12 12月 2017
12-Ara-2017
2 Likes

@peternlewis?

Hey @appeltaart,

Hopefully Peter will chime in with a convenient method of doing this natively with Keyboard Maestro.

@martin has shown it's not too difficult with Python.

It's also quite easy with the shell.

Paste Localized Date with the Shell 1.00.kmmacros (5.5 KB)

type man strftime in the Terminal.app to see the relevant metacharacters – they differ a bit from the ICU codes that KM uses.

Type locale -a in the Terminal.app to find publicly available localization codes.

-Chris

2 Likes

Keyboard Maestro uses the system locale. There is currently no way to specify the locale for the tokens.

So a script solution is your best bet at this point.

1 Like

It works! Thanks for all the help. This is a great forum.

4 Likes

Instead of the variable Plus1Day I did use %ICUDateTimePlus%1%Days%MMMM dd, yyyy%. However this does not give an English output, the name of the month is in Dutch.

  1. How do I need to change date '+%B %d, %Y' to get the date of tomorrow via Execute Shell Script?
  2. How to do this with plus 1 month?
  3. How to do this with plus 1 year?

I googled for "Shell Script Date Counting" but I am absolutely no Shell expert, so I would appreciate some help.

Schermafbeelding 2021-08-26 om 21.34.37

@ccstone

Hey @appeltaart,

The more you study the easier it gets to find the right language for searching, but when you start out you don't even have basic vocabulary.

date -v+1d '+%B %d, %Y'

date -v+1m '+%B %d, %Y'

date -v+1y '+%B %d, %Y'

Generally it's a good idea to start out with the man page in the Terminal:

man date

Learn your way around the man page viewer a little bit – for instance:

q == Quit
/ == Search forward
n == Find Next (when Search is active)
f == Forward 1 page
b == Back 1 page
j == Scroll Down
k == Scroll Up

Don't spend forever in the man page looking at things you don't understand, but use it to improve your knowledge of a command and its vocabulary.

If I seriously want to search a man page I open it in a BBEdit Shell Worksheet and use BBEdit's prodigious search capabilities.

If I don't find what I want pretty quickly I move on to Google.

To find out more about your task try this search:

shell add day to date

The very first hit showed my method and another.

-Chris

2 Likes

Thanks for the instructions, Chris! Right now I have the macro working like I wanted.

I'll start with your post when I want to do something in the Terminal in the future.

Maybe off-topic but I know that the Terminal can be really powerful, so the fear of doing something wrong (as a beginner) did keep me from using it, or testing things that you can find via Google. Anyway I am happy with your help, thanks!
@ccstone