Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Bob
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Bob
Commits
2ba68c1c
Verified
Commit
2ba68c1c
authored
1 month ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix(translation): fixes in datastruct
parent
3b91ff9d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/example2/pages/de.yaml
+12
-10
12 additions, 10 deletions
examples/example2/pages/de.yaml
examples/example2/pages/en.yaml
+1
-1
1 addition, 1 deletion
examples/example2/pages/en.yaml
source/translate/main.go
+22
-31
22 additions, 31 deletions
source/translate/main.go
with
35 additions
and
42 deletions
examples/example2/pages/de.yaml
+
12
−
10
View file @
2ba68c1c
...
@@ -15,7 +15,7 @@ test.html:
...
@@ -15,7 +15,7 @@ test.html:
title
:
Ja
title
:
Ja
anchors
:
anchors
:
-
id
:
mmmm
-
id
:
mmmm
href
:
mmmm
href
:
this is a yummy link
hreflang
:
"
"
hreflang
:
"
"
title
:
"
"
title
:
"
"
-
id
:
yes-a-html
-
id
:
yes-a-html
...
@@ -56,24 +56,26 @@ test.html:
...
@@ -56,24 +56,26 @@ test.html:
-
text
:
Kundin
-
text
:
Kundin
id
:
customer
id
:
customer
-
text
:
PLZ
-
text
:
PLZ
id
:
city
id
:
zipcode
-
text
:
Stadt
-
text
:
Stadt
id
:
c
ountr
y
id
:
c
it
y
-
text
:
Land
-
text
:
Land
id
:
street
id
:
country
-
text
:
Straße
-
text
:
Straße
id
:
order-state
id
:
street
-
text
:
Zustand der Bestellung
-
text
:
Zustand der Bestellung
id
:
w
or
kflow
-state
id
:
or
der
-state
-
text
:
Workflow-Status
-
text
:
Workflow-Status
id
:
total
id
:
workflow-state
-
text
:
gesamt
-
text
:
gesamt
id
:
company
id
:
total
-
text
:
firma
-
text
:
firma
id
:
c
hannel-order-number
id
:
c
ompany
-
text
:
Bestellnummer des Kanals
-
text
:
Bestellnummer des Kanals
id
:
resubmission-date
id
:
channel-order-number
-
text
:
Datum der erneuten Einreichung
-
text
:
Datum der erneuten Einreichung
id
:
resubmission-date
-
text
:
Art der Zahlung
id
:
payment-type
id
:
payment-type
translations
:
translations
:
-
id
:
the-translation
-
id
:
the-translation
...
...
This diff is collapsed.
Click to expand it.
examples/example2/pages/en.yaml
+
1
−
1
View file @
2ba68c1c
...
@@ -15,7 +15,7 @@ test.html:
...
@@ -15,7 +15,7 @@ test.html:
title
:
"
yes"
title
:
"
yes"
anchors
:
anchors
:
-
id
:
mmmm
-
id
:
mmmm
href
:
mmmm
href
:
this is a yummy link
hreflang
:
"
"
hreflang
:
"
"
title
:
"
"
title
:
"
"
-
id
:
yes-a-html
-
id
:
yes-a-html
...
...
This diff is collapsed.
Click to expand it.
source/translate/main.go
+
22
−
31
View file @
2ba68c1c
...
@@ -167,83 +167,74 @@ func collectUniqueTexts(storage *types.PageDataStorage) []string {
...
@@ -167,83 +167,74 @@ func collectUniqueTexts(storage *types.PageDataStorage) []string {
func
applyTranslations
(
page
,
origin
types
.
PageData
,
translations
map
[
string
]
string
)
types
.
PageData
{
func
applyTranslations
(
page
,
origin
types
.
PageData
,
translations
map
[
string
]
string
)
types
.
PageData
{
newPage
:=
page
newPage
:=
page
// PageData.Title
if
t
,
ok
:=
translations
[
origin
.
Title
];
ok
{
originPageTitle
:=
origin
.
Title
if
t
,
ok
:=
translations
[
originPageTitle
];
ok
{
newPage
.
Title
=
t
newPage
.
Title
=
t
}
else
{
}
else
{
newPage
.
Title
=
origin
Page
Title
newPage
.
Title
=
origin
.
Title
}
}
// PageData.Meta
// PageData.Meta
newMeta
:=
make
(
map
[
string
]
string
)
newMeta
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
page
.
Meta
{
for
k
,
v
:=
range
origin
.
Meta
{
vv
:=
origin
.
Meta
[
k
]
new
Meta
[
k
]
=
v
if
t
,
ok
:=
translations
[
v
v
];
ok
{
if
t
,
ok
:=
translations
[
v
];
ok
{
newMeta
[
k
]
=
t
newMeta
[
k
]
=
t
}
else
{
newMeta
[
k
]
=
v
}
}
}
}
newPage
.
Meta
=
newMeta
newPage
.
Meta
=
newMeta
newPage
.
Text
=
make
([]
types
.
Text
,
len
(
origin
.
Text
))
newPage
.
Text
=
make
([]
types
.
Text
,
len
(
origin
.
Text
))
for
i
,
t
:=
range
origin
.
Text
{
for
i
,
t
:=
range
origin
.
Text
{
tt
:=
origin
.
Text
[
i
]
if
tr
,
ok
:=
translations
[
tt
.
Text
];
ok
{
newPage
.
Text
[
i
]
=
t
if
tr
,
ok
:=
translations
[
origin
.
Text
[
i
]
.
Text
];
ok
{
newPage
.
Text
[
i
]
.
Text
=
tr
newPage
.
Text
[
i
]
.
Text
=
tr
}
else
{
newPage
.
Text
[
i
]
.
Text
=
t
.
Text
}
}
}
}
newPage
.
Images
=
make
([]
types
.
Image
,
len
(
origin
.
Images
))
newPage
.
Images
=
make
([]
types
.
Image
,
len
(
origin
.
Images
))
for
i
,
img
:=
range
origin
.
Images
{
for
i
,
img
:=
range
origin
.
Images
{
newPage
.
Images
[
i
]
=
img
if
tr
,
ok
:=
translations
[
img
.
Alt
];
ok
{
if
tr
,
ok
:=
translations
[
img
.
Alt
];
ok
{
newPage
.
Images
[
i
]
.
Alt
=
tr
newPage
.
Images
[
i
]
.
Alt
=
tr
}
else
{
newPage
.
Images
[
i
]
.
Alt
=
img
.
Alt
}
}
if
tr
,
ok
:=
translations
[
img
.
Title
];
ok
{
if
tr
,
ok
:=
translations
[
img
.
Title
];
ok
{
newPage
.
Images
[
i
]
.
Title
=
tr
newPage
.
Images
[
i
]
.
Title
=
tr
}
else
{
newPage
.
Images
[
i
]
.
Title
=
img
.
Title
}
}
}
}
newPage
.
Anchors
=
make
([]
types
.
Anchor
,
len
(
origin
.
Anchors
))
newPage
.
Anchors
=
make
([]
types
.
Anchor
,
len
(
origin
.
Anchors
))
for
i
,
anc
:=
range
origin
.
Anchors
{
for
i
,
anc
:=
range
origin
.
Anchors
{
newPage
.
Anchors
[
i
]
=
anc
if
tr
,
ok
:=
translations
[
anc
.
Title
];
ok
{
if
tr
,
ok
:=
translations
[
anc
.
Title
];
ok
{
newPage
.
Anchors
[
i
]
.
Title
=
tr
newPage
.
Anchors
[
i
]
.
Title
=
tr
}
else
{
newPage
.
Anchors
[
i
]
.
Title
=
anc
.
Title
}
}
}
}
// Translations: KeyValues (nur falls Value ein String ist)
// Translations: KeyValues (nur falls Value ein String ist)
newPage
.
Translations
=
make
([]
types
.
Translations
,
len
(
origin
.
Translations
))
newPage
.
Translations
=
make
([]
types
.
Translations
,
len
(
origin
.
Translations
))
for
i
,
t
:=
range
origin
.
Translations
{
for
i
,
t
:=
range
origin
.
Translations
{
newKV
:=
make
(
map
[
string
]
interface
{})
for
k
,
v
:=
range
t
.
KeyValues
{
if
s
,
ok
:=
v
.
(
string
);
ok
{
originStr
,
ok
:=
origin
.
Translations
[
i
]
.
KeyValues
[
k
]
.
(
string
)
newPage
.
Translations
[
i
]
=
t
if
!
ok
{
originStr
=
s
}
if
tr
,
found
:=
translations
[
originStr
];
found
{
newKV
:=
make
(
map
[
string
]
any
)
for
k
,
v
:=
range
t
.
KeyValues
{
newKV
[
k
]
=
v
switch
v
:=
v
.
(
type
)
{
case
string
:
if
tr
,
found
:=
translations
[
v
];
found
{
newKV
[
k
]
=
tr
newKV
[
k
]
=
tr
}
else
{
}
else
{
newKV
[
k
]
=
s
newKV
[
k
]
=
v
}
}
}
else
{
newKV
[
k
]
=
v
}
}
}
}
newPage
.
Translations
[
i
]
.
KeyValues
=
newKV
newPage
.
Translations
[
i
]
.
KeyValues
=
newKV
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment