Browse Source

Changes date locale to follow VS Code by default

Adds a "system" option to follow the system locale
main
Eric Amodio 3 years ago
parent
commit
4c49bcb9bf
4 changed files with 16 additions and 12 deletions
  1. +8
    -8
      README.md
  2. +1
    -1
      package.json
  3. +2
    -2
      src/extension.ts
  4. +5
    -1
      src/system/date.ts

+ 8
- 8
README.md View File

@ -997,14 +997,14 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
## Date & Time Settings [#](#date--time-settings- 'Date & Time Settings')
| Name | Description |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gitlens.defaultDateFormat` | Specifies how absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for supported formats |
| `gitlens.defaultDateLocale` | Specifies the locale, a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag), to use for date formatting. For example: 'en-US' = US English, 'en-GB' = British English, 'de-DE' = German, 'ko-KR' = Korean, 'ar-EG' = Arabic, 'ja-JP = Japanese, etc. |
| `gitlens.defaultDateShortFormat` | Specifies how short absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for supported formats |
| `gitlens.defaultDateSource` | Specifies whether commit dates should use the authored or committed date |
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
| `gitlens.defaultTimeFormat` | Specifies how times will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for supported formats |
| Name | Description |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gitlens.defaultDateFormat` | Specifies how absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for supported formats |
| `gitlens.defaultDateLocale` | Specifies the locale, a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag), to use for date formatting, defaults to the VS Code locale. Use `system` to follow the current system locale, or choose a specific locale, e.g `en-US` — US English, `en-GB` — British English, `de-DE` — German, 'ja-JP = Japanese, etc. |
| `gitlens.defaultDateShortFormat` | Specifies how short absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for supported formats |
| `gitlens.defaultDateSource` | Specifies whether commit dates should use the authored or committed date |
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
| `gitlens.defaultTimeFormat` | Specifies how times will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for supported formats |
## Menu & Toolbar Settings [#](#menu--toolbar-settings- 'Menu & Toolbar Settings')

+ 1
- 1
package.json View File

@ -2443,7 +2443,7 @@
"null"
],
"default": null,
"markdownDescription": "Specifies the locale, a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag), to use for date formatting. For example: 'en-US' = US English, 'en-GB' = British English, 'de-DE' = German, 'ko-KR' = Korean, 'ar-EG' = Arabic, 'ja-JP = Japanese, etc.",
"markdownDescription": "Specifies the locale, a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag), to use for date formatting, defaults to the VS Code locale. Use `system` to follow the current system locale, or choose a specific locale, e.g `en-US` — US English, `en-GB` — British English, `de-DE` — German, 'ja-JP = Japanese, etc.",
"scope": "window",
"order": 21
},

+ 2
- 2
src/extension.ts View File

@ -97,11 +97,11 @@ export async function activate(context: ExtensionContext): Promise
Configuration.configure(context);
const cfg = configuration.get();
setDefaultDateLocales(cfg.defaultDateLocale);
setDefaultDateLocales(cfg.defaultDateLocale ?? env.language);
context.subscriptions.push(
configuration.onDidChange(e => {
if (!e.affectsConfiguration('gitlens.defaultDateLocale')) return;
setDefaultDateLocales(configuration.get('defaultDateLocale'));
setDefaultDateLocales(configuration.get('defaultDateLocale', undefined, env.language));
}),
);

+ 5
- 1
src/system/date.ts View File

@ -24,7 +24,11 @@ let defaultShortRelativeTimeFormat: InstanceType
export function setDefaultDateLocales(locales: string | string[] | null | undefined) {
if (typeof locales === 'string') {
defaultLocales = [locales];
if (locales === 'system') {
defaultLocales = undefined;
} else {
defaultLocales = [locales];
}
} else {
defaultLocales = locales ?? undefined;
}

Loading…
Cancel
Save