Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added companies list localization #774

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/pages/_home/companies/_config.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Company = {
export type Company = {
/* URL to your company website */
url: string;
/* Image path to your company logo */
Expand Down Expand Up @@ -113,3 +113,20 @@ export const companies: Company[] = [
alt: "Blindtyping",
},
];

const japaneseCompanies: Company[] = [
{
url: "https://hapins.net/",
src: "ja/hapins.png",
alt: "HapInS",
},
];

const koreanCompanies: Company[] = [];

export const localeToCompaniesMap: Record<string, Company[]> = {
ru: companies,
en: companies,
ja: japaneseCompanies,
ko: koreanCompanies,
};
9 changes: 4 additions & 5 deletions src/pages/_home/companies/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React, { useMemo } from "react";
import React from "react";
// It's utility, not hook =)
import getBaseUrl from "@docusaurus/useBaseUrl";
import { translate } from "@docusaurus/Translate";
import Marquee from "react-fast-marquee";
import { shuffle } from "lodash-es";
import { Section } from "@site/src/shared/ui";

import { companies } from "./_config";
import styles from "./styles.module.scss";
import { useCompanies } from "./use-companies";

export const Companies = () => {
const companiesShuffled = useMemo(() => shuffle(companies), []);
const companies = useCompanies();

return (
<Section
Expand All @@ -19,7 +18,7 @@ export const Companies = () => {
containerClass={styles.rootContainer}
>
<Marquee pauseOnHover>
{companiesShuffled.map(({ url, src, alt }) => (
{companies.map(({ url, src, alt }) => (
<a
key={src}
className={styles.item}
Expand Down
38 changes: 38 additions & 0 deletions src/pages/_home/companies/use-companies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import { useMemo } from "react";
import { shuffle } from "lodash-es";
import { DEFAULT_LOCALE } from "@site/config/docusaurus/consts";
import { companies, localeToCompaniesMap } from "./_config";

const MIN_COMPANIES_AMOUNT = 8;

export const useCompanies = () => {
const { i18n } = useDocusaurusContext();

const shuffledLocaleCompanies = useMemo(() => {
const localeCompanies =
localeToCompaniesMap[i18n.currentLocale] || companies;

const isEnoughLocaleCompanies =
localeCompanies.length >= MIN_COMPANIES_AMOUNT;

const isDefaultLocale = i18n.currentLocale === DEFAULT_LOCALE;

const isNeedAddDefaultLocaleCompanies =
!isEnoughLocaleCompanies && !isDefaultLocale;

const fullLocaleCompanies = isNeedAddDefaultLocaleCompanies
? [
...localeCompanies,
...companies.slice(
0,
MIN_COMPANIES_AMOUNT - localeCompanies.length,
),
]
: localeCompanies;

return shuffle(fullLocaleCompanies);
}, [i18n.currentLocale]);

return shuffledLocaleCompanies;
};
Binary file added static/img/companies/ja/hapins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading