class Messages {
  get(js, code) {
    if (typeof code != "string") {
      console.error(`[Messages] invalid code !`);
      return "Error";
    }

    if (code.slice(0, 4) == "msg:") {
      code = code.slice(4);
    }

    if (!pmbDojo.messages) {
      console.error(`[Messages] pmbDojo.messages not loaded !`);
      return code;
    }

    let message = "";
    try {
      message = pmbDojo.messages.getMessage(js, code);
    } catch (e) {
      console.error("[Messages] js = " + js + "code = " + code);
      console.error("[Messages] error = " + e);
      return code;
    }
    return "" != message ? message : code;
  }
}

export default new Messages();
