How To Expand Dates in Other Languages with TextExpander

World Dates

Do you ever have to type out the date? Maybe in an email, a file name, or meeting notes? Depending on where and why you need a date, it has a certain format, the month as a word (March) versus a number (03), for example.

With TextExpander you can set up the ordering of a date snippet with relative ease:

  • Year – Month – Day

or

  • Month, Day Year

What you cannot as easily control is how the date presents. Let’s say you run your system in English, but you live and work in Germany. When TextExpander expands dates, you get “Monday” instead of “Montag” which can leave you feeling melancholisch.

As with macOS, TextExpander uses the Language & Region system preferences settings to determine day and month names for dates. If English is at the top of your Preferred Languages list, that’s what TextExpander will use.

How to expand dates in a language other than your system’s default

You can achieve this by using a shell script snippet and explicitly setting the language:

  1. Choose File -> New Snippet
  2. Set the Content: popup to “Shell Script”
  3. Set the snippet content to:
    #!/bin/bash
    LANG=de_DE.UTF-8
    date "+%d %B %Y"
    
  4. Set the abbreviation to whatever you like
  5. Type your abbreviation in another app

Now, rather than “Monday July 25 2016”, you’ll get “Montag 25 Juli 2016”, which should leave you feeling froh.

You can use any of the standard TextExpander date macros in place of the “%d %B %Y” above. Please note that you can’t use TextExpander’s date math macros, which are a way to quickly expand a date several days in the future, or past.

To use a language other than German, change the “de_DE” portion of the snippet content to the two character ISO 639-1 language code for your language, followed by an underscore, followed by your two character ISO 3166-1 country code. Here are some examples:

  • French: fr_FR
  • Canadian French: fr_CA
  • Italian: it_IT
  • Japanese: ja_JP
  • Portuguese: pt_PT
  • Brazilian Portuguese: pt_BR

The Future

I know what you’re thinking: can’t we do this in JavaScript so that it works on my iPhone, iPad, and Windows machine? The answer is: not yet, but we hope soon.

The JavaScript engine in the Safari Developer Preview supports the ECMA Internationalization Specification. As the JavaScript engines are updated in macOS and iOS, we expect it will be possible to create a JavaScript snippet like this:

var date = new Date(Date.UTC(2013, 1, 1, 14, 0, 0));
var options = {
    weekday: "long", year: "numeric", month: "short",
    day: "numeric", hour: "2-digit", minute: "2-digit"
};
date.toLocaleDateString("de-DE", options);

That snippet will expand to:

Freitag, 1. Feb. 2013, 06:00

And that should make you euphorisch!