i18nHelper.js 778 B

12345678910111213141516171819202122
  1. import line_i18n from "line-i18n";
  2. import { LocalizedStrings } from "./localizedStringsService";
  3. const StringTypes = line_i18n.StringTypes;
  4. export const i18nHelper = Object.freeze({
  5. i18n: (identifier) => {
  6. var opts = identifier.split(':');
  7. var type = opts[0].toLowerCase();
  8. var id = opts[1];
  9. if (StringTypes.ERROR === type) {
  10. return LocalizedStrings.getError(id);
  11. } else if (StringTypes.MESSAGE === type) {
  12. return LocalizedStrings.getMessage(id);
  13. } else if (StringTypes.UI === type) {
  14. return LocalizedStrings.getUI(id);
  15. } else {
  16. console.warn("A string has been passed to the i18n helper function that was not in the form type:id -> " + identifier);
  17. return LocalizedStrings.getString(identifier, type);
  18. }
  19. }
  20. });