-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
32-transform-to-and-from-xliff-2 #33
Conversation
|
||
type unit struct { | ||
ID string `xml:"id,attr"` | ||
Notes *[]note `xml:"notes>note"` // Set as pointer to avoid empty <notes></notes> when marshalling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried many solutions, but this is the only one that works: avoiding <notes></notes>
when marshaling xliff2
struct with no Notes
.
If there is a better way/ways I am happy to hear about them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try omitempty
Notes *[]note `xml:"notes>note"` // Set as pointer to avoid empty <notes></notes> when marshalling. | |
Notes []note `xml:"notes>note,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not work, already tried
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en">
<file>
<unit id="Welcome">
<notes>
<note category="description">To welcome a new visitor</note>
</notes>
<segment>
<source>Welcome to our website!</source>
</segment>
</unit>
<unit id="Error">
<notes>
<note category="description">To inform the user of an error</note>
</notes>
<segment>
<source>Something went wrong. Please try again later.</source>
</segment>
</unit>
<unit id="Feedback">
<notes></notes>
<segment>
<source>We appreciate your feedback. Thank you for using our service.</source>
</segment>
</unit>
</file>
</xliff>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not possible using field tag golang/go#7233
It is possible by implementing xml.Marshaler
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good enough as it is (*[]note
) or []note `xml:"notes>note,omitempty"
leaving empty <notes></notes>
when there is no description ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*[]note
return nil, fmt.Errorf("marshal model.Messages to XLIFF 2 formatted XML: %w", err) | ||
} | ||
|
||
dataWithHeader := append([]byte(xml.Header), data...) // prepend generic XML header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding XML Declaration is recommended
https://www.w3.org/TR/xml/#sec-prolog-dtd
</unit> | ||
</file> | ||
</xliff>`), | ||
want: model.Messages{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to call it expected?
expected: model.Messages...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you are right, but I guess it should be in a separate PR, as if I change I should change in all files to remain consistency
}{ | ||
{ | ||
name: "All OK", | ||
data: []byte(`<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here maybe input?
pkg/convert/xliff2_test.go
Outdated
} | ||
|
||
// Matches a substring that starts with > and ends with < with zero or more whitespace in between. | ||
re := regexp.MustCompile(`>(\s*)<`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create a test helper function if you use it in multiple tests.
func equalXml(t *testing.T, expected, actual []byte) boolean {
t.Helper()
// ....
}
* #19 Transform-to-and-from-POT * #19 Transform-to-and-from-POT * #19 Tidy * #19 minor fixes * #19 minor fixes * #19 minor fixes * #19 fixes * #19 changed multiline msgdid and msgstr * #19 modified ToPot function * #19 fixes * #19 modified multiline functionality * #19 added error to lexer function * #19 added quoted string support in lex function and made fixes * #19 changed fully Lex function because of gocognit * #19 changed PoTag -> poTag * #19 changed identifiers to private * #19 added comment multiline support * #19 fixes * #34 transform to and from XMB * 17-transform-to-and-from-arb (#20) * File-upload2 (#13) * 21-download-file (#22) * Instrument traces (OpenTelemetry) (#24) * #27 Upgraded earthly to 0.7 (#28) * #25 Added configuration from various sources (#29) * 32-transform-to-and-from-xliff-2 (#33) * 18-transform-to-and-from-angularlocalize (#31) * Renamed table test fields for consistency (#38) --------- Co-authored-by: Vladislavs Perkaņuks <69954124+VladislavsPerkanuks@users.noreply.github.com>
No description provided.