Skip to content

Commit

Permalink
Move direction to localeConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Feb 1, 2021
1 parent cdf3b9d commit b140ef2
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ declare module '@generated/i18n' {
defaultLocale: string;
locales: [string, ...string[]];
currentLocale: string;
localeConfigs: Record<string, {label: string}>;
localeConfigs: Record<string, {label: string; direction: string}>;
};
export default i18n;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-theme-classic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function docusaurusThemeClassic(
): Plugin<null, unknown> {
const {
siteConfig: {themeConfig},
i18n: {direction},
i18n: {currentLocale, localeConfigs},
} = context;
const {colorMode, prism: {additionalLanguages = []} = {}} = themeConfig || {};
const {customCss} = options || {};
Expand Down Expand Up @@ -95,7 +95,8 @@ export default function docusaurusThemeClassic(
translateThemeConfig,

getClientModules() {
const infimaBundleSuffix = direction === 'rtl' ? '-rtl' : '';
const infimaBundleSuffix =
localeConfigs[currentLocale].direction === 'rtl' ? '-rtl' : '';

const modules = [
require.resolve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function CanonicalUrlHeaders({permalink}: {permalink?: string}) {
export default function LayoutHead(props: Props): JSX.Element {
const {
siteConfig,
i18n: {currentLocale, direction},
i18n: {currentLocale, localeConfigs},
} = useDocusaurusContext();
const {
favicon,
Expand All @@ -87,11 +87,12 @@ export default function LayoutHead(props: Props): JSX.Element {
// See https://github.com/facebook/docusaurus/issues/3317#issuecomment-754661855
// const htmlLang = currentLocale.split('-')[0];
const htmlLang = currentLocale; // should we allow the user to override htmlLang with localeConfig?
const htmlDir = localeConfigs[currentLocale].direction;

return (
<>
<Head>
<html lang={htmlLang} dir={direction} />
<html lang={htmlLang} dir={htmlDir} />
{metaTitle && <title>{metaTitle}</title>}
{metaTitle && <meta property="og:title" content={metaTitle} />}
{favicon && <link rel="shortcut icon" href={faviconUrl} />}
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 @@ -94,13 +94,13 @@ export type TranslationFiles = TranslationFile[];

export type I18nLocaleConfig = {
label: string;
direction: 'ltr' | 'rtl';
};

export type I18nConfig = {
defaultLocale: string;
locales: [string, ...string[]];
localeConfigs: Record<string, I18nLocaleConfig>;
direction: 'ltr' | 'rtl';
};

export type I18n = I18nConfig & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Object {
"favicon": "img/docusaurus.ico",
"i18n": Object {
"defaultLocale": "en",
"direction": "ltr",
"localeConfigs": Object {},
"locales": Array [
"en",
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus/src/server/__tests__/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('loadI18n', () => {
locales: ['en'],
currentLocale: 'en',
localeConfigs: testLocaleConfigsFor(['en']),
direction: 'ltr',
});
});

Expand Down
6 changes: 1 addition & 5 deletions packages/docusaurus/src/server/configValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const DEFAULT_I18N_CONFIG: I18nConfig = {
defaultLocale: DEFAULT_I18N_LOCALE,
locales: [DEFAULT_I18N_LOCALE],
localeConfigs: {},
direction: 'ltr',
};

export const DEFAULT_CONFIG: Pick<
Expand All @@ -37,7 +36,6 @@ export const DEFAULT_CONFIG: Pick<
| 'titleDelimiter'
| 'noIndex'
| 'baseUrlIssueBanner'
| 'direction'
> = {
i18n: DEFAULT_I18N_CONFIG,
onBrokenLinks: 'throw',
Expand Down Expand Up @@ -73,6 +71,7 @@ const PresetSchema = Joi.alternatives().try(

const LocaleConfigSchema = Joi.object({
label: Joi.string(),
direction: Joi.string().equal('ltr', 'rtl').default('ltr'),
});

const I18N_CONFIG_SCHEMA = Joi.object<I18nConfig>({
Expand All @@ -81,9 +80,6 @@ const I18N_CONFIG_SCHEMA = Joi.object<I18nConfig>({
localeConfigs: Joi.object()
.pattern(/.*/, LocaleConfigSchema)
.default(DEFAULT_I18N_CONFIG.localeConfigs),
direction: Joi.string()
.equal('ltr', 'rtl')
.default(DEFAULT_I18N_CONFIG.direction),
})
.optional()
.default(DEFAULT_I18N_CONFIG);
Expand Down
3 changes: 2 additions & 1 deletion website/docs/api/docusaurus.config.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ module.exports = {
localeConfigs: {
en: {
label: 'English',
direction: 'rtl', // Defaults to `ltr`
},
fr: {
label: 'Français',
direction: 'rtl', // Defaults to `ltr`
},
},
direction: 'rtl', // Defaults to `ltr`
},
};
```
Expand Down

0 comments on commit b140ef2

Please sign in to comment.