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

docs: add localisation example to demo #309

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

chrisvxd
Copy link
Member

@chrisvxd chrisvxd commented Dec 21, 2023

Quick demo of localisation using new demo route under /locales/[locale]/[...puckPath].

Kapture.2023-12-21.at.19.23.37.mp4

It uses object fields and context to provide localisation on the Heading component.

Things that should be included in this demo

  • Localisations for Hero fields
  • Localisations for other fields

Things that would generally improve localisations

Copy link

vercel bot commented Dec 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
puck-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 21, 2023 7:24pm
puck-docs ✅ Ready (Inspect) Visit Preview Dec 21, 2023 7:24pm

@chrisvxd chrisvxd changed the title docs: add localisation example to docs docs: add localisation example to demo Dec 21, 2023
@chrisvxd
Copy link
Member Author

Dropping updated approach based on discussions

export type TestProps = {
  language: "en" | "fr" | "es";
  title: {
    en?: string;
    fr?: string;
    es?: string;
  };
};

export const Test: ComponentConfig<TestProps> = {
  resolveFields: (data) => {
    const title: ObjectField<TestProps["title"]> = {
      type: "object",
      objectFields: {},
    };

    if (data.props.language === "en") {
      title.objectFields.en = {
        type: "text",
      };
    } else if (data.props.language === "fr") {
      title.objectFields.fr = {
        type: "text",
      };
    } else if (data.props.language === "es") {
      title.objectFields.es = {
        type: "text",
      };
    }

    return {
      language: {
        type: "radio",
        options: [
          { label: "English", value: "en" },
          { label: "French", value: "fr" },
          { label: "Spanish", value: "es" },
        ],
      },
      title,
    };
  },
  render: ({ language, title, puck: { isEditing } }) => {
    const i18nLang = useCurrentLocale();
    return <div>{title[isEditing ? language : i18nLang]}</div>;
  },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant