Skip to content

Commit

Permalink
formats: Add Format.JS support
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Jan 4, 2024
1 parent 739b0cc commit 67936b5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Not yet released.

* :ref:`check-perl-brace-format` quality check.
* :doc:`/formats/moko`.
* :doc:`/formats/formatjs`.

**Improvements**

Expand Down
52 changes: 52 additions & 0 deletions docs/formats/formatjs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.. _formatjs:

Format.JS JSON file
-------------------

.. versionadded:: 5.4

File format used when translating Format.JS and React-Intl applications.

.. seealso::

:doc:`tt:formats/json`,
`Format.JS Message Extraction <https://formatjs.io/docs/getting-started/message-extraction>`_

Example file:

.. code-block:: json
{
{
"hak27d": {
"defaultMessage": "Control Panel",
"description": "title of control panel section"
},
"haqsd": {
"defaultMessage": "Delete user {name}",
"description": "delete button"
},
"19hjs": {
"defaultMessage": "New Password",
"description": "placeholder text"
},
"explicit-id": {
"defaultMessage": "Confirm Password",
"description": "placeholder text"
}
}
Weblate configuration
+++++++++++++++++++++
+-------------------------------------------------------------------+
| Typical Weblate :ref:`component` |
+================================+==================================+
| File mask | ``src/lang/*.json`` |
+--------------------------------+----------------------------------+
| Monolingual base language file | ``src/extracted/en.json`` |
+--------------------------------+----------------------------------+
| Template for new translations | `Empty` |
+--------------------------------+----------------------------------+
| File format | `Format.JS JSON file` |
+--------------------------------+----------------------------------+
1 change: 1 addition & 0 deletions weblate/formats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class FormatsConf(AppConf):
"weblate.formats.ttkit.GoI18V2JSONFormat",
"weblate.formats.ttkit.GoTextFormat",
"weblate.formats.ttkit.ARBFormat",
"weblate.formats.ttkit.FormatJSFormat",
"weblate.formats.ttkit.CSVFormat",
"weblate.formats.ttkit.CSVUtf8Format",
"weblate.formats.ttkit.CSVSimpleFormat",
Expand Down
8 changes: 8 additions & 0 deletions weblate/formats/ttkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,14 @@ class GoTextFormat(JSONFormat):
supports_plural: bool = True


class FormatJSFormat(JSONFormat):
name = gettext_lazy("Format.JS JSON file")
format_id = "formatjs"
loader = ("jsonl10n", "FormatJSJsonFile")
autoload = ()
check_flags = ("icu-message-format",)


class CSVFormat(TTKitFormat):
name = gettext_lazy("CSV file")
format_id = "csv"
Expand Down

0 comments on commit 67936b5

Please sign in to comment.