Skip to content

Commit

Permalink
fix: support danish locale (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
imprashast authored Jul 4, 2024
1 parent 6afb9fd commit e0e9124
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/attention/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import IconClose16 from '@warp-ds/icons/react/close-16';
import { activeAttentionType, getVariant, pointingAtDirection, useAutoUpdatePosition } from '../../_helpers/attention.js';
import { activateI18n } from '../../i18n.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand Down Expand Up @@ -53,7 +54,7 @@ export function Attention(props: AttentionProps) {
...rest
} = props;

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

const wrapperClasses = classNames(ccAttention.base, variantClasses[getVariant(rest, variantClasses)].wrapper);

Expand Down
1 change: 1 addition & 0 deletions packages/attention/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"attention.aria.callout\":\"En grøn taleboble der introducerer noget nyt\",\"attention.aria.close\":\"Luk\",\"attention.aria.highlight\":\"En opmærksomhedsskabende taleboble med vigtig information\",\"attention.aria.pointingDown\":\"peger nedad\",\"attention.aria.pointingLeft\":\"peger til venstre\",\"attention.aria.pointingRight\":\"peger til højre\",\"attention.aria.pointingUp\":\"peger opad\",\"attention.aria.popover\":\"En hvid taleboble med mere information\",\"attention.aria.tooltip\":\"En sort taleboble med flere oplysninger\"}");
3 changes: 2 additions & 1 deletion packages/breadcrumbs/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { breadcrumbs as ccBreadcrumbs } from '@warp-ds/css/component-classes';

import { activateI18n } from '../../i18n.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand All @@ -14,7 +15,7 @@ import type { BreadcrumbsProps } from './props.js';
export const Breadcrumbs = (props: BreadcrumbsProps) => {
const { children, className, ...rest } = props;

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

const ariaLabel =
props['aria-label'] ||
Expand Down
1 change: 1 addition & 0 deletions packages/breadcrumbs/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"breadcrumbs.ariaLabel\":\"Du er her\"}");
3 changes: 2 additions & 1 deletion packages/button/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { button as ccButton } from '@warp-ds/css/component-classes';

import { activateI18n } from '../../i18n.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand Down Expand Up @@ -88,7 +89,7 @@ export const Button = forwardRef<HTMLButtonElement | AnchorHTMLAttributes<HTMLAn
}
};

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

const ariaValueTextLoading = i18n._(
/*i18n*/ {
Expand Down
1 change: 1 addition & 0 deletions packages/button/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"button.aria.loading\":\"Indlæser...\"}");
3 changes: 2 additions & 1 deletion packages/combobox/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { activateI18n } from '../../i18n.js';
import { TextField } from '../../textfield/src/index.js';
import { useId } from '../../utils/src/index.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand All @@ -34,7 +35,7 @@ export const Combobox = forwardRef<HTMLInputElement, ComboboxProps>(({ id: pid,
const inputContainerRef = useRef<HTMLDivElement | null>(null);
const containerRef = useRef<HTMLDivElement | null>(null);

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

// Options list open boolean
const [isOpen, setOpen] = useState(false);
Expand Down
1 change: 1 addition & 0 deletions packages/combobox/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"combobox.aria.pluralResults\":[[\"numResults\",\"plural\",{\"one\":[\"#\",\" resultat\"],\"other\":[\"#\",\" resultater\"]}]],\"combobox.aria.noResults\":\"Ingen resultater\"}");
9 changes: 5 additions & 4 deletions packages/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { i18n, Messages } from '@lingui/core';

export const supportedLocales = ['en', 'nb', 'fi'] as const;
export const supportedLocales = ['en', 'nb', 'fi', 'da'] as const;
type SupportedLocale = (typeof supportedLocales)[number];

export const defaultLocale = 'en';
Expand Down Expand Up @@ -29,16 +29,17 @@ export function detectLocale(): SupportedLocale {
}
}

export const getMessages = (locale: SupportedLocale, enMsg: Messages, nbMsg: Messages, fiMsg: Messages) => {
export const getMessages = (locale: SupportedLocale, enMsg: Messages, nbMsg: Messages, fiMsg: Messages, daMsg: Messages) => {
if (locale === 'nb') return nbMsg;
if (locale === 'fi') return fiMsg;
if (locale === 'da') return daMsg;
// Default to English
return enMsg;
};

export const activateI18n = (enMessages: Messages, nbMessages: Messages, fiMessages: Messages) => {
export const activateI18n = (enMessages: Messages, nbMessages: Messages, fiMessages: Messages, daMessages: Messages) => {
const locale = detectLocale();
const messages = getMessages(locale, enMessages, nbMessages, fiMessages);
const messages = getMessages(locale, enMessages, nbMessages, fiMessages, daMessages);
i18n.load(locale, messages);
i18n.activate(locale);
};
3 changes: 2 additions & 1 deletion packages/modal/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setup, teardown } from 'scroll-doctor';
import { activateI18n } from '../../i18n.js';
import { useId } from '../../utils/src/index.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand All @@ -24,7 +25,7 @@ export const Modal = ({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelled
const id = useId(props.id);
const closeButtonRef = useRef<HTMLButtonElement>(null);

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

useEffect(
() =>
Expand Down
1 change: 1 addition & 0 deletions packages/modal/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"modal.aria.back\":\"Tilbage\",\"modal.aria.close\":\"Luk\"}");
3 changes: 2 additions & 1 deletion packages/pagination/src/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { activateI18n } from '../../i18n.js';

import CurrentPage from './CurrentPage.js';
import FirstPage from './FirstPage.js';
import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand Down Expand Up @@ -41,7 +42,7 @@ export type PaginationProps = {

export const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
({ currentPage, numPages, lastPage, createHref, className, onChange, noFollow, ...props }, ref) => {
activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

if (!createHref) {
throw new TypeError('createHref is undefined');
Expand Down
1 change: 1 addition & 0 deletions packages/pagination/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"pagination.aria.first-page\":\"Første side\",\"pagination.aria.icon-suffix\":\"ikon\",\"pagination.aria.next-page\":\"Næste side\",\"pagination.label.current-page\":[\"Side \",[\"currentPage\"]],\"pagination.aria.page\":[\"Side \",[\"currentPage\"]],\"pagination.aria.pagination\":\"Sider\",\"pagination.aria.prev-page\":\"Forrige side\"}");
3 changes: 2 additions & 1 deletion packages/pill/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import IconClose16 from '@warp-ds/icons/react/close-16';

import { activateI18n } from '../../i18n.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
import type { PillProps } from './props.js';

export function Pill(props: PillProps) {
activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);
return (
<div className={ccPill.pill}>
<button
Expand Down
1 change: 1 addition & 0 deletions packages/pill/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"pill.aria.openFilter\":\"Åbn filter\",\"pill.aria.removeFilter\":[\"Fjern filter \",[\"label\"]]}");
3 changes: 2 additions & 1 deletion packages/select/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import IconChevronDown16 from '@warp-ds/icons/react/chevron-down-16';
import { activateI18n } from '../../i18n.js';
import { useId } from '../../utils/src/index.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand All @@ -16,7 +17,7 @@ import type { SelectProps } from './props.js';
const setup = (props) => {
const { className, invalid, id, hint, always, label, style, optional, readOnly, disabled, ...rest } = props;

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

const helpId = hint ? `${id}__hint` : undefined;

Expand Down
1 change: 1 addition & 0 deletions packages/select/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"select.label.optional\":\"(valgfrit)\"}");
1 change: 1 addition & 0 deletions packages/steps/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"steps.aria.emptyCircle\":\"Tom cirkel\",\"steps.aria.active\":\"Trinindikator aktiv cirkel\",\"steps.aria.completed\":\"Trinindikator fuldført cirkel\"}");
3 changes: 2 additions & 1 deletion packages/steps/src/step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import IconCheck16 from '@warp-ds/icons/react/check-16';
import { activateI18n } from '../../i18n.js';

import { StepsContext } from './component.js';
import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand Down Expand Up @@ -60,7 +61,7 @@ export interface StepProps {
}

export function Step(props: StepProps) {
activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

const { active, completed, children } = props;
const StepsProps = useContext(StepsContext);
Expand Down
3 changes: 2 additions & 1 deletion packages/textarea/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { input as ccInput, label as ccLabel, helpText as ccHelpText } from '@war
import { activateI18n } from '../../i18n.js';
import { useId } from '../../utils/src/index.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand All @@ -33,7 +34,7 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>((props, f
...rest
} = props;

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

const id = useId(providedId);
const ref = useRef<HTMLTextAreaElement | null>(null);
Expand Down
1 change: 1 addition & 0 deletions packages/textarea/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"textarea.label.optional\":\"(valgfrit)\"}");
3 changes: 2 additions & 1 deletion packages/textfield/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { input as ccInput, label as ccLabel, helpText as ccHelpText } from '@war
import { activateI18n } from '../../i18n.js';
import { useId } from '../../utils/src/index.js';

import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
Expand All @@ -28,7 +29,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>((props, re
...rest
} = props;

activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

const id = useId(providedId);
const helpId = helpText ? `${id}__hint` : undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/textfield/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"textfield.label.optional\":\"(valgfrit)\"}");
3 changes: 2 additions & 1 deletion packages/toggle/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { activateI18n } from '../../i18n.js';
import { useId } from '../../utils/src/index.js';

import { Item } from './item.js';
import { messages as daMessages } from './locales/da/messages.mjs';
import { messages as enMessages } from './locales/en/messages.mjs';
import { messages as fiMessages } from './locales/fi/messages.mjs';
import { messages as nbMessages } from './locales/nb/messages.mjs';
import { ToggleProps } from './props.js';
import type { ToggleEntry } from './props.js';

function Title({ id, title, optional }) {
activateI18n(enMessages, nbMessages, fiMessages);
activateI18n(enMessages, nbMessages, fiMessages, daMessages);

return (
<legend id={`${id}__title`} className={ccLabel.label}>
Expand Down
1 change: 1 addition & 0 deletions packages/toggle/src/locales/da/messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*eslint-disable*/export const messages=JSON.parse("{\"toggle.label.optional\":\"(valgfrit)\"}");

0 comments on commit e0e9124

Please sign in to comment.