Skip to content

Commit

Permalink
i18nDir -> localizationDir
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 27, 2022
1 parent 9fb2fc9 commit 3fd1b1b
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const getPlugin = async (
i18n: I18n = DefaultI18N,
) => {
const generatedFilesDir: string = path.resolve(siteDir, '.docusaurus');
const i18nDir = path.join(siteDir, i18n.path, i18n.currentLocale);
const localizationDir = path.join(siteDir, i18n.path, i18n.currentLocale);
const siteConfig = {
title: 'Hello',
baseUrl: '/',
Expand All @@ -83,7 +83,7 @@ const getPlugin = async (
siteConfig,
generatedFilesDir,
i18n,
i18nDir,
localizationDir,
} as LoadContext,
validateOptions({
validate: normalizePluginOptions as Validate<
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export default async function pluginContentBlog(
siteDir,
siteConfig,
generatedFilesDir,
i18nDir,
localizationDir,
i18n: {currentLocale},
} = context;
const {onBrokenMarkdownLinks, baseUrl} = siteConfig;

const contentPaths: BlogContentPaths = {
contentPath: path.resolve(siteDir, options.path),
contentPathLocalized: getPluginI18nPath({
i18nDir,
localizationDir,
pluginName: 'docusaurus-plugin-content-blog',
pluginId: options.id,
}),
Expand Down
10 changes: 5 additions & 5 deletions packages/docusaurus-plugin-content-docs/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ export async function cliDocsVersionCommand(

await Promise.all(
i18n.locales.map(async (locale) => {
// TODO duplicated logic from core; we need to support customization per-
// locale in the future
const i18nDir = path.resolve(siteDir, i18n.path, locale);
// TODO duplicated logic from core, so duplicate comment as well: we need
// to support customization per-locale in the future
const localizationDir = path.resolve(siteDir, i18n.path, locale);
// Copy docs files.
const docsDir =
locale === i18n.defaultLocale
? path.resolve(siteDir, docsPath)
: getDocsDirPathLocalized({
i18nDir,
localizationDir,
pluginId,
versionName: CURRENT_VERSION_NAME,
});
Expand All @@ -116,7 +116,7 @@ export async function cliDocsVersionCommand(
locale === i18n.defaultLocale
? getVersionDocsDirPath(siteDir, pluginId, version)
: getDocsDirPathLocalized({
i18nDir,
localizationDir,
pluginId,
versionName: version,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('readVersionsMetadata', () => {
siteDir: simpleSiteDir,
baseUrl: '/',
i18n: DefaultI18N,
i18nDir: path.join(simpleSiteDir, 'i18n/en'),
localizationDir: path.join(simpleSiteDir, 'i18n/en'),
} as LoadContext;

const vCurrent: VersionMetadata = {
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('readVersionsMetadata', () => {
siteDir: versionedSiteDir,
baseUrl: '/',
i18n: DefaultI18N,
i18nDir: path.join(versionedSiteDir, 'i18n/en'),
localizationDir: path.join(versionedSiteDir, 'i18n/en'),
} as LoadContext;

const vCurrent: VersionMetadata = {
Expand Down Expand Up @@ -639,7 +639,7 @@ describe('readVersionsMetadata', () => {
siteDir: versionedSiteDir,
baseUrl: '/',
i18n: DefaultI18N,
i18nDir: path.join(versionedSiteDir, 'i18n/en'),
localizationDir: path.join(versionedSiteDir, 'i18n/en'),
} as LoadContext;

const vCurrent: VersionMetadata = {
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-plugin-content-docs/src/versions/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ export function getVersionSidebarsPath(
}

export function getDocsDirPathLocalized({
i18nDir,
localizationDir,
pluginId,
versionName,
}: {
i18nDir: string;
localizationDir: string;
pluginId: string;
versionName: string;
}): string {
return getPluginI18nPath({
i18nDir,
localizationDir,
pluginName: 'docusaurus-plugin-content-docs',
pluginId,
subPaths: [
Expand Down Expand Up @@ -172,7 +172,7 @@ export async function getVersionMetadataPaths({
> {
const isCurrent = versionName === CURRENT_VERSION_NAME;
const contentPathLocalized = getDocsDirPathLocalized({
i18nDir: context.i18nDir,
localizationDir: context.localizationDir,
pluginId: options.id,
versionName,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getVersionEditUrls({
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
const editDirPathLocalized = options.editCurrentVersion
? getDocsDirPathLocalized({
i18nDir: context.i18nDir,
localizationDir: context.localizationDir,
versionName: CURRENT_VERSION_NAME,
pluginId: options.id,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-pages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export default function pluginContentPages(
[admonitions, options.admonitions],
]);
}
const {siteConfig, siteDir, generatedFilesDir, i18nDir} = context;
const {siteConfig, siteDir, generatedFilesDir, localizationDir} = context;

const contentPaths: PagesContentPaths = {
contentPath: path.resolve(siteDir, options.path),
contentPathLocalized: getPluginI18nPath({
i18nDir,
localizationDir,
pluginName: 'docusaurus-plugin-content-pages',
pluginId: options.id,
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-types/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export type LoadContext = {
* Directory where all source translations for the current locale can be found
* in. Constructed with `i18n.path` + `i18n.currentLocale.path` (e.g. i18n/en)
*/
i18nDir: string;
localizationDir: string;
/**
* Duplicated from `siteConfig.baseUrl`, but probably worth keeping. We mutate
* `siteConfig` to make `baseUrl` there localized as well, but that's mostly
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-utils/src/__tests__/i18nUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('getPluginI18nPath', () => {
it('gets correct path', () => {
expect(
getPluginI18nPath({
i18nDir: '<SITE_DIR>/i18n/zh-Hans',
localizationDir: '<SITE_DIR>/i18n/zh-Hans',
pluginName: 'plugin-content-docs',
pluginId: 'community',
subPaths: ['foo'],
Expand All @@ -77,7 +77,7 @@ describe('getPluginI18nPath', () => {
it('gets correct path for default plugin', () => {
expect(
getPluginI18nPath({
i18nDir: '<SITE_DIR>/i18n/zh-Hans',
localizationDir: '<SITE_DIR>/i18n/zh-Hans',
pluginName: 'plugin-content-docs',
subPaths: ['foo'],
}),
Expand All @@ -88,7 +88,7 @@ describe('getPluginI18nPath', () => {
it('gets correct path when no sub-paths', () => {
expect(
getPluginI18nPath({
i18nDir: '<SITE_DIR>/i18n/zh-Hans',
localizationDir: '<SITE_DIR>/i18n/zh-Hans',
pluginName: 'plugin-content-docs',
}),
).toMatchInlineSnapshot(`"<SITE_DIR>/i18n/zh-Hans/plugin-content-docs"`);
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-utils/src/i18nUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ export function updateTranslationFileMessages(
* expect everything it needs for translations to be found under this path.
*/
export function getPluginI18nPath({
i18nDir,
localizationDir,
pluginName,
pluginId = DEFAULT_PLUGIN_ID,
subPaths = [],
}: {
i18nDir: string;
localizationDir: string;
pluginName: string;
pluginId?: string | undefined;
subPaths?: string[];
}): string {
return path.join(
i18nDir,
localizationDir,
// Make it convenient to use for single-instance
// ie: return "docs", not "docs-default" nor "docs/default"
`${pluginName}${pluginId === DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`,
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function start(
logger.error(err.stack);
});
}, 500);
const {siteConfig, plugins, i18nDir} = props;
const {siteConfig, plugins, localizationDir} = props;

const normalizeToSiteDir = (filepath: string) => {
if (filepath && path.isAbsolute(filepath)) {
Expand All @@ -95,7 +95,7 @@ export async function start(
.filter(Boolean)
.map(normalizeToSiteDir);

const pathsToWatch = [...pluginPaths, props.siteConfigPath, i18nDir];
const pathsToWatch = [...pluginPaths, props.siteConfigPath, localizationDir];

const pollingOptions = {
usePolling: !!cliOptions.poll,
Expand Down
12 changes: 6 additions & 6 deletions packages/docusaurus/src/commands/writeTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async function getExtraSourceCodeFilePaths(): Promise<string[]> {
}

async function writePluginTranslationFiles({
i18nDir,
localizationDir,
plugin,
options,
}: {
i18nDir: string;
localizationDir: string;
plugin: InitializedPlugin;
options: WriteTranslationsOptions;
}) {
Expand All @@ -64,7 +64,7 @@ async function writePluginTranslationFiles({
await Promise.all(
translationFiles.map(async (translationFile) => {
await writePluginTranslations({
i18nDir,
localizationDir,
plugin,
translationFile,
options,
Expand All @@ -83,7 +83,7 @@ export async function writeTranslations(
config: options.config,
locale: options.locale,
});
const {i18nDir} = context;
const {localizationDir} = context;
const plugins = await initPlugins(context);

const locale = options.locale ?? context.i18n.defaultLocale;
Expand Down Expand Up @@ -114,11 +114,11 @@ Available locales are: ${context.i18n.locales.join(',')}.`,
defaultCodeMessages,
});

await writeCodeTranslations({i18nDir}, codeTranslations, options);
await writeCodeTranslations({localizationDir}, codeTranslations, options);

await Promise.all(
plugins.map(async (plugin) => {
await writePluginTranslationFiles({i18nDir, plugin, options});
await writePluginTranslationFiles({localizationDir, plugin, options});
}),
);
}
12 changes: 6 additions & 6 deletions packages/docusaurus/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export async function loadContext(

const siteConfig: DocusaurusConfig = {...initialSiteConfig, baseUrl};

// TODO allow customizing i18nDir per-locale
const i18nDir = path.resolve(siteDir, i18n.path, i18n.currentLocale);
// TODO allow customizing localizationDir per-locale
const localizationDir = path.resolve(siteDir, i18n.path, i18n.currentLocale);

const codeTranslationFileContent =
(await readCodeTranslationFileContent({i18nDir})) ?? {};
(await readCodeTranslationFileContent({localizationDir})) ?? {};

// We only need key->message for code translations
const codeTranslations = _.mapValues(
Expand All @@ -100,7 +100,7 @@ export async function loadContext(
return {
siteDir,
generatedFilesDir,
i18nDir,
localizationDir,
siteConfig,
siteConfigPath,
outDir,
Expand All @@ -126,7 +126,7 @@ export async function load(options: LoadContextOptions): Promise<Props> {
outDir,
baseUrl,
i18n,
i18nDir,
localizationDir,
codeTranslations: siteCodeTranslations,
} = context;
const {plugins, pluginsRouteConfigs, globalData} = await loadPlugins(context);
Expand Down Expand Up @@ -248,7 +248,7 @@ ${Object.entries(registry)
outDir,
baseUrl,
i18n,
i18nDir,
localizationDir,
generatedFilesDir,
routes: pluginsRouteConfigs,
routesPaths,
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/server/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function loadPlugins(context: LoadContext): Promise<{
const translationFiles = await Promise.all(
rawTranslationFiles.map((translationFile) =>
localizePluginTranslationFile({
i18nDir: context.i18nDir,
localizationDir: context.localizationDir,
translationFile,
plugin,
}),
Expand Down
Loading

0 comments on commit 3fd1b1b

Please sign in to comment.