translate-agent / translate

Enables translation for Cloud-native systems
Other
2 stars 0 forks source link

Change XLIFF1.2 and XLIFF2 Import Behaviour #100

Closed egijasp closed 1 year ago

egijasp commented 1 year ago

uploaded two schema=xliff_12 files, source language en-US (https://github.com/localizely/angular-i18n-example/blob/main/src/locale/messages.xlf), target language fr (https://github.com/localizely/angular-i18n-example/blob/main/src/locale/messages.fr.xlf).

returned listMessages, but in the fr file the message are in english :

[
    {
        "language": "en-US",
        "messages": [
            {
                "id": "message.simple",
                "message": "{A simple message.}",
                "description": "Simple message example",
                "fuzzy": false
            },
            {
                "id": "message.argument",
                "message": "{Hi, ! πŸ‘‹}",
                "description": "Argument message example",
                "fuzzy": false
            },
            {
                "id": "message.plural",
                "message": "{{VAR_PLURAL, plural, one { item} other { items}}}",
                "description": "Plural message example",
                "fuzzy": false
            },
            {
                "id": "message.gender",
                "message": "{{VAR_SELECT, select, male {Mr } female {Mrs } other {Client }}}",
                "description": "Gender message example",
                "fuzzy": false
            },
            {
                "id": "message.number-format",
                "message": "{Formatted number: }",
                "description": "Formatted number message example",
                "fuzzy": false
            },
            {
                "id": "message.date-format",
                "message": "{Formatted date: }",
                "description": "Formatted date message example",
                "fuzzy": false
            },
            {
                "id": "message.component-argument",
                "message": "{Made with ❀️ by }",
                "description": "Component argument message example",
                "fuzzy": false
            }
        ]
    },
    {
        "language": "fr",
        "messages": [
            {
                "id": "message.simple",
                "message": "{A simple message.}",
                "description": "Simple message example",
                "fuzzy": false
            },
            {
                "id": "message.argument",
                "message": "{Hi, ! πŸ‘‹}",
                "description": "Argument message example",
                "fuzzy": false
            },
            {
                "id": "message.plural",
                "message": "{{VAR_PLURAL, plural, one { item} other { items}}}",
                "description": "Plural message example",
                "fuzzy": false
            },
            {
                "id": "message.gender",
                "message": "{{VAR_SELECT, select, male {Mr } female {Mrs } other {Client }}}",
                "description": "Gender message example",
                "fuzzy": false
            },
            {
                "id": "message.number-format",
                "message": "{Formatted number: }",
                "description": "Formatted number message example",
                "fuzzy": false
            },
            {
                "id": "message.date-format",
                "message": "{Formatted date: }",
                "description": "Formatted date message example",
                "fuzzy": false
            },
            {
                "id": "message.component-argument",
                "message": "{Made with ❀️ by }",
                "description": "Component argument message example",
                "fuzzy": false
            }
        ]
    }
]
VladislavsPerkanuks commented 1 year ago

for me it seems we cannot do anything without modifying model.Messages structure so the situation:

Converting from XLIFF 1.2 to model.Messages

there is an original extracted xliff1.2 file

...
<file source-language="en" > // <- messages.language
      <trans-unit id="1"> // <- messages[n].id
        <source>Hello, world!</source> // <- messages[n].message
      </trans-unit>
...

now if someone already translated it

...
 <file source-language="en" target-language="ru"> // <- messages.language = ???
      <trans-unit id="1">  // <- messages[n].id
        <source>Hello, world!</source> 
        <target>ΠŸΡ€ΠΈΠ²Π΅Ρ‚, ΠΌΠΈΡ€!</target> // <- message[n].message ???
      </trans-unit>
...

and more fun when only partial translation is in file

 <file source-language="en" target-language="ru">// <- messages.language = ???
      <trans-unit id="1">  // <- messages[n].id
        <source>Hello, world!</source> 
        <target>ΠŸΡ€ΠΈΠ²Π΅Ρ‚, ΠΌΠΈΡ€!</target> // <- message[n].message ???
      </trans-unit>
      <trans-unit id="2">  // <- messages[n].id
        <source>Hello, world2!</source>  // <- ???
      </trans-unit>

if we use target as message[n].message then there could be situations where we loose messages, which should be unacceptable

Converting from model.Messages to XLIFF 1.2

An XLIFF document is normally a bilingual file. It has one source language (the language of the original extracted file), and one target language.

as model.Messages has only one message, then we cannot properly transform our modell.Message to XLIFF1.2.

Expected output when exporting translations

      <trans-unit id="1">
        <source>Hello, world!</source> 
        <target>ΠŸΡ€ΠΈΠ²Π΅Ρ‚, ΠΌΠΈΡ€!</target>
      </trans-unit>

Possible outputs with our model.Messages

      <trans-unit id="1">
        <source>Hello, world!</source>  // or <source>ΠŸΡ€ΠΈΠ²Π΅Ρ‚, ΠΌΠΈΡ€!</source> 
      </trans-unit>

or

      <trans-unit id="1">
        <target>Hello, world!</target>  // or <target>ΠŸΡ€ΠΈΠ²Π΅Ρ‚, ΠΌΠΈΡ€!</target> 
      </trans-unit>

Possible Solution

Change our models

type Messages struct {
    Language language.Tag
        OriginalLang language.Tag  // or just a bool
    Messages []Message
}

type Message struct {
    ID          string
    PluralID    string
        Source string // text to be translated in original language
    Translated     string // translated text in wanted language (Messages.Language)
    Description string
    Fuzzy       bool
}
VladislavsPerkanuks commented 1 year ago

Same thing goes for XLIFF2

janishorsts commented 1 year ago

Reality is simpler: