How to use the @shopgate/engage/core.i18n.ready function in @shopgate/engage

To help you get started, we’ve selected a few @shopgate/engage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / libraries / common / components / I18n / components / Translate / index.jsx View on Github external
const Translate = ({
  string,
  children,
  params,
  className,
  role,
  ...rest
}) => {
  if (typeof string !== 'string' || string.length === 0) {
    return string;
  }

  if (!i18n.ready) {
    return <span role="{role}">{string}</span>;
  }

  // When the input string is malformed, rather return the original string then raising an error.
  let formatted = string;

  try {
    // First replace every occurrence of a translation key with a separator.
    const separator = '__%S%__';
    const childrenArray = React.Children.toArray(children);

    const values = childrenArray.reduce((obj, child) =&gt; (child.props &amp;&amp; child.props.forKey ? {
      ...obj,
      [child.props.forKey]: separator,
    } : obj), { ...params });
github shopgate / pwa / libraries / common / components / I18n / components / FormatPrice / index.jsx View on Github external
FormatPrice.format = ({ price, currency, fractions }) => {
  if (!i18n.ready) {
    return price;
  }

  return i18n.price(price, currency, fractions);
};
github shopgate / pwa / libraries / common / components / I18n / components / FormatDate / index.jsx View on Github external
FormatDate.format = ({ timestamp, format }) => {
  if (!i18n.ready) {
    return timestamp;
  }

  return i18n.date(timestamp, format);
};
github shopgate / pwa / libraries / common / components / I18n / components / FormatNumber / index.jsx View on Github external
FormatNumber.format = (props) => {
  if (!i18n.ready) {
    return props.number;
  }

  return i18n.number(props.number, props.fractions);
};
github shopgate / pwa / libraries / common / components / I18n / components / FormatTime / index.jsx View on Github external
FormatTime.format = ({ timestamp, format }) => {
  if (!i18n.ready) {
    return timestamp;
  }

  return i18n.time(timestamp, format);
};