translation.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. class translation {
  2. #content;
  3. translated;
  4. /**
  5. * This create new translation. Translation store content of the
  6. * translation, make avairable to format translated phrase and also
  7. * store that translation was found in the phrasebook.
  8. *
  9. * @param {string} content - Content of the translation.
  10. * @param {bool} translated - True when translation could be found.
  11. */
  12. constructor(content, translated = true) {
  13. if (typeof(content) !== "string") {
  14. throw new TypeError("Translated content must be string.");
  15. }
  16. if (typeof(translated) !== "boolean") {
  17. throw new TypeError("Result of translation must be boolean.");
  18. }
  19. this.#content = content;
  20. this.translated = translated;
  21. }
  22. /**
  23. * This convert transiation to string.
  24. *
  25. * @returns {string} - Content of the translation.
  26. */
  27. toString() {
  28. return this.#content;
  29. }
  30. /**
  31. * @returns {string} - Content of the translation.
  32. */
  33. get text() {
  34. return this.#content;
  35. }
  36. /**
  37. * @returns {bool} - True when translation was found, false when not.
  38. */
  39. get valid() {
  40. return this.translated;
  41. }
  42. }
  43. exports.translation = translation;