Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bjcp-2015-styleguide
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Frank Steinberg
bjcp-2015-styleguide
Commits
b88e8926
Commit
b88e8926
authored
5 years ago
by
Frank Steinberg
Browse files
Options
Downloads
Patches
Plain Diff
Completed de-auto translation for the first time.
parent
f05dd3d9
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+4
-2
4 additions, 2 deletions
Makefile
bjcp-2015-styleguide-de-auto.xml
+1633
-1616
1633 additions, 1616 deletions
bjcp-2015-styleguide-de-auto.xml
translate
+134
-0
134 additions, 0 deletions
translate
with
1771 additions
and
1618 deletions
Makefile
+
4
−
2
View file @
b88e8926
...
@@ -48,7 +48,7 @@ web/bjcp-2015-styleguide-orig.xml: bjcp-2015-styleguide-orig.xml
...
@@ -48,7 +48,7 @@ web/bjcp-2015-styleguide-orig.xml: bjcp-2015-styleguide-orig.xml
web/bjcp-2015-styleguide-de.xml
:
bjcp-2015-styleguide-de.xml
web/bjcp-2015-styleguide-de.xml
:
bjcp-2015-styleguide-de.xml
cp
bjcp-2015-styleguide-de.xml web/
cp
bjcp-2015-styleguide-de.xml web/
web/bjcp-2015-styleguide-de-auto.xml
:
web/bjcp-2015-styleguide-de-auto.xml
:
bjcp-2015-styleguide-de-auto.xml
cp
bjcp-2015-styleguide-de-auto.xml web/bjcp-2015-styleguide-de-auto.xml
cp
bjcp-2015-styleguide-de-auto.xml web/bjcp-2015-styleguide-de-auto.xml
web/bjcp-2015-styleguide-orig.html
:
bjcp-2015-styleguide-orig.html
web/bjcp-2015-styleguide-orig.html
:
bjcp-2015-styleguide-orig.html
...
@@ -97,7 +97,9 @@ distclean: clean
...
@@ -97,7 +97,9 @@ distclean: clean
@
rm
-rf
cache
@
rm
-rf
cache
@
echo
"complete cleanup done"
@
echo
"complete cleanup done"
delete-glossary
:
delete-glossary
:
curl
-X
DELETE
-H
"Authorization: Bearer "
`
gcloud auth application-default print-access-token
`
https://translation.googleapis.com/v3beta1/projects/
$(
PROJECTID
)
/locations/
$(
LOCATION
)
/glossaries/
$(
GLOSSARYID
)
curl
-X
DELETE
-H
"Authorization: Bearer "
`
gcloud auth application-default print-access-token
`
https://translation.googleapis.com/v3beta1/projects/
$(
PROJECTID
)
/locations/
$(
LOCATION
)
/glossaries/
$(
GLOSSARYID
)
bjcp-2015-styleguide-de-auto.xml
:
bjcp-2015-styleguide-orig.xml
cat
bjcp-2015-styleguide-orig.xml | ./translate | xmllint
--format
-
>
bjcp-2015-styleguide-de-auto.xml
This diff is collapsed.
Click to expand it.
bjcp-2015-styleguide-de-auto.xml
+
1633
−
1616
View file @
b88e8926
This diff is collapsed.
Click to expand it.
translate
0 → 100755
+
134
−
0
View file @
b88e8926
#!/usr/bin/env python3
#
# NOTE: This works only for the author and his personal Google account.
# Other users would have to apply their own adjustments.
#
import
re
import
sys
import
getopt
from
google.cloud
import
translate_v3beta1
as
translate
from
google.cloud
import
storage
project_id
=
"
bjcp-styleguide-1570890297003
"
glossary_id
=
'
bjcp-en-de-glossary
'
location
=
'
us-central1
'
target_language
=
'
de
'
language_codes
=
[
'
en
'
,
target_language
]
glossary_uri
=
'
gs://bjcp-styleguide/glossary-en-%s.csv
'
%
target_language
bucket_name
=
'
bjcp-styleguide
'
client
=
None
storage_client
=
None
def
createGlossary
():
glossary_name
=
client
.
glossary_path
(
project_id
,
location
,
glossary_id
)
language_codes_set
=
translate
.
types
.
Glossary
.
LanguageCodesSet
(
language_codes
=
language_codes
)
gcs_source
=
translate
.
types
.
GcsSource
(
input_uri
=
glossary_uri
)
input_config
=
translate
.
types
.
GlossaryInputConfig
(
gcs_source
=
gcs_source
)
glossary
=
translate
.
types
.
Glossary
(
name
=
glossary_name
,
language_codes_set
=
language_codes_set
,
input_config
=
input_config
)
location_path
=
client
.
location_path
(
project_id
,
location
)
operation
=
client
.
create_glossary
(
parent
=
location_path
,
glossary
=
glossary
)
result
=
operation
.
result
(
timeout
=
90
)
print
(
'
createGlossary() result: {}
'
.
format
(
result
.
name
))
#print('Input Uri: {}'.format(result.input_config.gcs_source.input_uri))
def
showGlossaries
():
location_path
=
client
.
location_path
(
project_id
,
location
)
for
glossary
in
client
.
list_glossaries
(
location_path
):
print
(
'
Name: {}
'
.
format
(
glossary
.
name
))
print
(
'
Entry count: {}
'
.
format
(
glossary
.
entry_count
))
print
(
'
Input uri: {}
'
.
format
(
glossary
.
input_config
.
gcs_source
.
input_uri
))
for
language_code
in
glossary
.
language_codes_set
.
language_codes
:
print
(
'
Language code: {}
'
.
format
(
language_code
))
def
deleteGlossary
():
return
False
def
checkGlossary
():
return
False
def
getGlossaryConfig
():
glossary
=
client
.
glossary_path
(
project_id
,
location
,
glossary_id
)
glossary_config
=
translate
.
types
.
TranslateTextGlossaryConfig
(
glossary
=
glossary
)
return
glossary_config
def
getTranslation
(
text
,
glossary_config
=
None
):
location_path
=
client
.
location_path
(
project_id
,
location
)
result
=
client
.
translate_text
(
parent
=
location_path
,
contents
=
[
text
],
mime_type
=
'
text/html
'
,
source_language_code
=
'
en
'
,
target_language_code
=
target_language
,
glossary_config
=
glossary_config
)
if
(
glossary_config
):
return
result
.
glossary_translations
[
0
].
translated_text
else
:
return
result
.
translations
[
0
].
translated_text
client
=
translate
.
TranslationServiceClient
()
storage_client
=
storage
.
Client
()
def
main
(
argv
):
try
:
opts
,
args
=
getopt
.
getopt
(
argv
,
"
h
"
,[
"
cg
"
,
"
ug
"
])
except
getopt
.
GetoptError
:
print
(
'
translate [ --cg | --ug] [file]
'
)
sys
.
exit
(
2
)
for
opt
,
arg
in
opts
:
if
opt
==
'
-h
'
:
sys
.
exit
()
elif
opt
in
(
"
--cg
"
):
createGlossary
()
exit
(
0
)
elif
opt
in
(
"
--ug
"
):
updateGlossary
()
exit
(
0
)
if
len
(
args
)
>=
1
:
with
open
(
args
[
0
],
"
r
"
)
as
file
:
lines
=
file
.
readlines
()
else
:
lines
=
sys
.
stdin
.
readlines
()
g
=
getGlossaryConfig
()
for
line
in
lines
:
if
(
re
.
match
(
r
"
*<(bjcp:|)(p|p class.*|h1|h2|h3|h4|h5|td|li|name|description|overall-impression|aroma|appearance|flavor|mouthfeel|comments|history|characteristic-ingredients|style-comparison|entry-instructions|commercial-examples)>.
"
,
line
)):
r
=
getTranslation
(
line
,
g
)
print
(
r
)
sys
.
stderr
.
write
(
"
.
"
)
sys
.
stderr
.
flush
()
#r = "TRANSLATE: %s" % line
else
:
print
(
line
)
#print("ORIG: %s" % line)
if
__name__
==
"
__main__
"
:
main
(
sys
.
argv
[
1
:])
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