How to use the intl-messageformat function in intl-messageformat

To help you get started, we’ve selected a few intl-messageformat 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 opencollective / opencollective-api / server / lib / twitter.js View on Github external
Become a backer! 😃`,
    },
  };

  if (message) {
    messages['en-US'][template] = message;
  }

  if (!messages['en-US'][template]) {
    console.error('Invalid tweet template', template);
    return;
  }

  const thankyou = '\n\nThank you! 🙏';
  const compiled = new IntlMessageFormat(messages['en-US'][template], 'en-US');
  let tweet = compiled.format(data);

  if (template === 'monthlyStats') {
    // A URL always takes 23 chars (+ space)
    if (tweet.length < 280 - 24 - thankyou.length) {
      tweet += thankyou;
    }
  }
  return tweet;
};
github formatjs / react-intl / test / unit / format.ts View on Github external
it('formats AST message with placeholders', () => {
      const {locale, messages} = config;
      const mf = new IntlMessageFormat(messages.ast_var, locale);
      const values = {name: 'Eric'};

      expect(formatMessage({id: 'ast_var'}, values)).toBe(mf.format(values));
    });
github bitnami-labs / cabin / src / utils / LocalesUtils.js View on Github external
static getLocalizedString(id, values) {
    try {
      const lang = this.getLanguage();
      const locale = this.locales[id] || this.defaultLocales[id];
      const formater = new IntlMessageFormat(locale, lang);
      return formater.format(values);
    } catch (e) {
      console.error(`Localized string error for key: ${id} n`);
      return '';
    }
  }
github olegnn / react-shopping-cart / src / localization / index.js View on Github external
const createMessage = (pattern: string, language: string, params: Object): string =>
  params.currency != null
    ? new IntlMessageFormat(
        pattern, language, {
            number: {
              CUR: {
                  style   : 'currency',
                  currency: params.currency,
              }
          }
        }
      ).format(params)
    : new IntlMessageFormat(
        pattern, language
      ).format(params);
github axross / axross.dev / src / pages / posts / [blogPostId].tsx View on Github external
content={blogPost.summary}
            key="og:description"
          />
          
          {availableLocales
            .filter(locale => locale !== currentLocale)
            .map(locale => (
              
            ))}
          
          
           {
              const imageURL = new URL(url.href);

              imageURL.pathname = "/static/profile.jpg";

              return imageURL.href;
github bcrumbs / booben / app / utils / index.js View on Github external
export const getLocalizedText = (localization, language, id, values = {}) =>
    new IntlMessageFormat(localization[id], language).format(values);
github gpbl / isomorphic500 / src / stores / HtmlHeadStore.js View on Github external
formatMessage(message, values={}) {
    const store = this.dispatcher.getStore("IntlStore");
    const msg = new IntlMessageFormat(store.getMessage(message), store.getLocales());
    return msg.format(values);
  }
github fresk-nc / VOX / app / lib / playerErrorReporter.js View on Github external
report(src, callback) {
        const removeBtnId = 0;
        const cancelBtnId = 1;

        showMessageBox({
            type: 'error',
            buttons: [
                new IntlMessageFormat(messages[locale]['playerError.remove'], locale).format(),
                new IntlMessageFormat(messages[locale]['common.cancel'], locale).format()
            ],
            cancelId: cancelBtnId,
            message: new IntlMessageFormat(messages[locale]['playerError.message'], locale).format(),
            detail: new IntlMessageFormat(messages[locale]['playerError.detail'], locale).format({ src })
        }, (buttonIndex) => {
            if (buttonIndex === removeBtnId) {
                callback();
            }
        });
    }
};
github alexkuz / redux-pagan / src / getLang.js View on Github external
memoizedI18nPartial.format = function(values) {
    const str = getLangString(locale, data, _path);
    const formatter = new IntlMessageFormat(str, locale);
    return formatter.format(values);
  }
github bpetetot / conference-hall / src / screens / search / results / searchResults.messages.js View on Github external
export default (key, values) => {
  const msg = new IntlMessageFormat(messages[key])
  return msg.format(values)
}

intl-messageformat

Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.

BSD-3-Clause
Latest version published 13 days ago

Package Health Score

100 / 100
Full package analysis