Skip to content

Commit cd02b04

Browse files
committed
fix: #133 update LOCALE config to cover overall locales
Update LOCALE inside config.ts to include html lang value and datetime locale values. Updated respective files and blog post. Closes: #133
1 parent c526157 commit cd02b04

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/components/Datetime.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ export default function Datetime({ datetime, size = "sm", className }: Props) {
3030
const FormattedDatetime = ({ datetime }: { datetime: string | Date }) => {
3131
const myDatetime = new Date(datetime);
3232

33-
const date = myDatetime.toLocaleDateString(LOCALE, {
33+
const date = myDatetime.toLocaleDateString(LOCALE.langTag, {
3434
year: "numeric",
3535
month: "long",
3636
day: "numeric",
3737
});
3838

39-
const time = myDatetime.toLocaleTimeString(LOCALE, {
39+
const time = myDatetime.toLocaleTimeString(LOCALE.langTag, {
4040
hour: "2-digit",
4141
minute: "2-digit",
4242
});

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export const SITE: Site = {
1010
postPerPage: 3,
1111
};
1212

13-
export const LOCALE = ["en-EN"]; // set to [] to use the environment default
13+
export const LOCALE = {
14+
lang: "en", // html lang code. Set this empty and default will be "en"
15+
langTag: ["en-EN"], // BCP 47 Language Tags. Set this empty [] to use the environment default
16+
} as const;
1417

1518
export const LOGO_IMAGE = {
1619
enable: false,

src/content/blog/how-to-configure-astropaper-theme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ You can configure the default locale used for the build (e.g., date format in th
5252

5353
```js
5454
// file: src/config.ts
55-
export const LOCALE = ["en-EN"]; // set to [] to use the environment default
55+
export const LOCALE = {
56+
lang: "en", // html lang code. Set this empty and default will be "en"
57+
langTag: ["en-EN"], // BCP 47 Language Tags. Set this empty [] to use the environment default
58+
} as const;
5659
```
5760

58-
You can even specify an array of locales for fallback languages. Leave it empty `[]` to use the environment default at _build-_ and _run-time_.
61+
`LOCALE.lang` will be used as HTML ISO Language code in `<html lang="en">`. If you don't specify this, default fallback will be set to `en`.
62+
`LOCALE.langTag` is used as [datetime locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString#locales). For this, you can specify an array of locales for fallback languages. Leave `LOCALE.langTag` empty `[]` to use the environment default at _build-_ and _run-time_.
5963

6064
## Configuring logo or title
6165

src/layouts/Layout.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import { SITE } from "@config";
2+
import { LOCALE, SITE } from "@config";
33
import "@styles/base.css";
44
import { ViewTransitions } from "astro:transitions";
55
@@ -28,7 +28,7 @@ const socialImageURL = new URL(
2828
---
2929

3030
<!doctype html>
31-
<html lang="en">
31+
<html lang=`${LOCALE.lang ?? "en"}`>
3232
<head>
3333
<meta charset="UTF-8" />
3434
<meta name="viewport" content="width=device-width" />

0 commit comments

Comments
 (0)