Translation memory models
These models are responsible for storing individual source strings and their translations.
graph TD
A[String] --> B[wagtail.Locale]
C[StringTranslation] --> B
C --> A
C --> D[TranslationContext]
D --> E[TranslatableObject]
F[Template]
style B stroke-dasharray: 5 5
style E stroke-dasharray: 5 5
String
Bases: Model
Represents a unique string of translatable text.
Attributes:
| Name | Type | Description |
|---|---|---|
locale |
ForeignKey to Locale
|
The locale of the string. |
data |
TextField
|
The string. |
data_hash |
UUIDField
|
A hash of the string, for more efficient indexing of long strings. |
Source code in wagtail_localize/models.py
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 | |
_get_data_hash(data)
classmethod
Generates a UUID from the given string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
string
|
The string to generate a hash of. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UUID |
The UUID hash. |
Source code in wagtail_localize/models.py
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 | |
as_value()
Creates a StringValue object from the contents of this string.
Returns:
| Name | Type | Description |
|---|---|---|
StringValue |
A StringValue instance with the content of this String. |
Source code in wagtail_localize/models.py
1463 1464 1465 1466 1467 1468 1469 1470 | |
from_value(locale, stringvalue)
classmethod
Gets or creates a String instance from a StringValue object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stringvalue |
StringValue
|
The value of the string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
The String instance that corresponds with the given stringvalue and locale. |
Source code in wagtail_localize/models.py
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
TranslationContext
Bases: Model
Represents a context that a string may be translated in.
Strings can be translated differently in different contexts. A context is a combination of an object and content path.
Attributes:
| Name | Type | Description |
|---|---|---|
object |
ForeignKey to TranslatableObject
|
The object. |
path |
TextField
|
The content path. |
field_path |
TextField
|
the field path. |
path_id |
UUIDField
|
A hash of the path for efficient indexing of long content paths. |
Source code in wagtail_localize/models.py
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 | |
_get_path_id(path)
classmethod
Generates a UUID from the given content path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
string
|
The content path to generate a hash of. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UUID |
The UUID hash. |
Source code in wagtail_localize/models.py
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 | |
get_field_path(instance)
Gets the field path for this context
Field path's were introduced in version 1.0, any contexts that were created before that release won't have one.
Source code in wagtail_localize/models.py
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 | |
Template
Bases: Model
A Template stores the structure of a RichTextField or RichTextBlock.
When a RichTextField/RichTextBlock is converted into segments, all translatable segments are stripped out of the block and stored as String instances. The remaining HTML is saved as a Template and is used for recombining the translated strings back into a rich text value.
Attributes:
| Name | Type | Description |
|---|---|---|
template |
TextField
|
The template value |
uuid |
UUIDField
|
A hash of the template contents for efficient indexing. |
template_format |
CharField
|
The format of the template (currently, only 'html' is supported). |
string_count |
PositiveIntegerField
|
The number of translatable stirngs that were extracted from the template. |
Source code in wagtail_localize/models.py
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 | |
from_value(template_value)
classmethod
Gets or creates a Template instance from a TemplateValue object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_value |
TemplateValue
|
The value of the template. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Template |
The Template instance that corresponds with the given template_value. |
Source code in wagtail_localize/models.py
1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 | |
StringTranslation
Bases: Model
Represents a translation of a string.
Attributes:
| Name | Type | Description |
|---|---|---|
translation_of |
ForeignKey to String
|
The String that this is a translation of. |
locale |
ForeignKey to Locale
|
The Locale of this translation. |
context |
ForeignKey to TranslationContext
|
The context that this translation was made in. This allows different fields/pages to have different translations of the same source string. |
data |
TextField
|
The translation. |
translation_type |
CharField with choices 'manual' or 'machine'
|
Whether the translationw as performed by a human or machine. |
tool_name |
CharField
|
The name of the tool that was used to make this translation. |
last_translated_by |
ForeignKey to User
|
The user who last updated this translation. |
created_at |
DateTimeField
|
The date/time that this translation was first created. |
updated_at |
DateFimeField
|
The date/time that this translation was last updated. |
has_error |
BooleanField
|
Set to True if the value of this translation has an error. We store translations with errors in case they were edited from an external system. This allows us to display the error in Wagtail. |
field_error |
TextField
|
If there was a database-level validation error while saving the translated object, that error is tored here. Note that this only makes sense if the context is not null. |
Source code in wagtail_localize/models.py
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 | |
from_text(translation_of, locale, context, data)
classmethod
Gets or creates a StringTranslation instance from the given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translation_of |
ForeignKey to String
|
The String that this is a translation of. |
required |
locale |
ForeignKey to Locale
|
The Locale of this translation. |
required |
context |
ForeignKey to TranslationContext
|
The context that this translation was made in. This allows different fields/pages to have different translations of the same source string. |
required |
data |
TextField
|
The translation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
The String instance that corresponds with the given stringvalue and locale. |
Source code in wagtail_localize/models.py
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 | |
get_comment()
Returns a comment to display to the user containing info on how and when the string was translated.
Returns:
| Name | Type | Description |
|---|---|---|
str |
A comment to display to the user. |
Source code in wagtail_localize/models.py
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 | |
get_error()
Returns a string containing any validation errors on the saved value.
Returns:
| Name | Type | Description |
|---|---|---|
str |
The validation error if there is one. |
|
None |
If there isn't an error. |
Source code in wagtail_localize/models.py
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 | |
set_field_error(error)
This sets the has_error/field_error fields to the value of the given ValidationError instance.
Note: If the given ValidationError contains multiple errors, only the first one is stored.
Note: This updates the database instance as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error |
ValidationError
|
The validation error to store. |
required |
Source code in wagtail_localize/models.py
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 | |