Skip to content

Commit

Permalink
Merge pull request #46 from sohosai/fix/sitemap-locale
Browse files Browse the repository at this point in the history
sitemapの生成時にlocale関連のエラーが発生している問題を修正
  • Loading branch information
Ryoga-exe authored Nov 17, 2023
2 parents 6e7fde9 + 5d94ff2 commit e8e5c49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import sitemap from "@astrojs/sitemap";

const defaultLocale = "ja";
const locales = {
ja: "ja-JP",
en: "en-US",
};
const UNIXlocalesMap = {
ja: "ja_JP",
en: "en_US",
};
Expand All @@ -28,6 +32,7 @@ export default defineConfig({
integrations: [
i18n({
defaultLocale,
UNIXlocalesMap,
locales,
}),
sitemap({
Expand Down
5 changes: 3 additions & 2 deletions src/utils/i18n/core/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { AstroIntegration } from "astro";
import type { i18nProps } from "../types";
import type { i18nAdapterConfig } from "../types";

export default function i18nPlus({ locales, defaultLocale }: i18nProps): AstroIntegration {
export default function i18nPlus({ locales, UNIXlocalesMap, defaultLocale }: i18nProps): AstroIntegration {
return {
name: "astro-i18n-plus",
hooks: {
"astro:config:setup": (options) => {
const config: i18nAdapterConfig = {
defaultLocale: defaultLocale,
supportedLocales: Object.keys(locales),
supportedPOSIXLocalesMap: locales,
supportedPOSIXLocalesMap: UNIXlocalesMap,
};

const stringifiedConfig = JSON.stringify(config);
Expand All @@ -36,6 +36,7 @@ export default function i18nPlus({ locales, defaultLocale }: i18nProps): AstroIn
const config: i18nAdapterConfig = {
defaultLocale: defaultLocale,
supportedLocales: Object.keys(locales),
supportedPOSIXLocalesMap: UNIXlocalesMap,
};

config.supportedLocales
Expand Down
2 changes: 2 additions & 0 deletions src/utils/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function i18n({
exclude = ["pages/api/**/*"],
locales,
defaultLocale,
UNIXlocalesMap,
}: i18nProps) {
return [
i18nAut({
Expand All @@ -18,6 +19,7 @@ export default function i18n({
i18nPlus({
locales,
defaultLocale,
UNIXlocalesMap,
}),
];
}
Expand Down
6 changes: 5 additions & 1 deletion src/utils/i18n/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { UserI18nConfig } from "astro-i18n-aut";

export type i18nAdapterConfig = {
defaultLocale: string;
supportedLocales: string[];
supportedPOSIXLocalesMap: { [key in string]: string };
};

export type { UserI18nConfig as i18nProps } from "astro-i18n-aut";
export type i18nProps = UserI18nConfig & {
UNIXlocalesMap: Record<string, string>;
};

0 comments on commit e8e5c49

Please sign in to comment.