Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tools
merge_translations
Commits
52acf88b
Commit
52acf88b
authored
Feb 22, 2014
by
Adam Schubert
Browse files
Initial commit
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
index.php
0 → 100644
View file @
52acf88b
<?php
class
merger
{
private
$merged
;
public
function
__construct
(
$sourceFile
,
$translationFile
)
{
$parsedSourceFile
=
$this
->
object2array
(
simplexml_load_string
(
$sourceFile
));
$parsedTranslationFile
=
$this
->
object2array
(
simplexml_load_string
(
$translationFile
));
foreach
(
$parsedSourceFile
[
'attribute'
]
AS
$key
=>
$vals
)
{
foreach
(
$vals
AS
$key2
=>
$vals2
)
{
if
(
is_array
(
$vals2
))
{
foreach
(
$vals2
AS
$key3
=>
$vals3
)
{
if
(
is_array
(
$vals3
))
{
foreach
(
$vals3
AS
$key4
=>
$vals4
)
{
$parsedTranslationFile
[
'attribute'
][
$key
][
$key2
][
$key3
][
$key4
][
'translation'
]
=
$vals4
[
'name'
];
}
}
else
{
//This is identifier i think...
}
}
}
else
{
$parsedTranslationFile
[
'attribute'
][
$key
][
'translation'
]
=
$vals2
;
//Order it propery
$parsedTranslationFile
[
'attribute'
][
$key
]
=
array_merge
(
array_flip
(
array
(
'name'
,
'translation'
,
'values'
)),
$parsedTranslationFile
[
'attribute'
][
$key
]);
}
}
}
$this
->
merged
=
$parsedTranslationFile
;
}
public
function
getXml
()
{
return
$this
->
array2xml
(
$this
->
merged
);
}
private
function
object2array
(
$object
)
{
return
@
json_decode
(
@
json_encode
(
$object
),
true
);
}
private
function
array2values
(
$arr
)
{
$a
=
array
();
foreach
(
$arr
AS
$k
=>
$v
)
{
$a
[]
=
$k
.
'="'
.
$v
.
'"'
;
}
return
implode
(
' '
,
$a
);
}
private
function
array2xml
(
$arr
)
{
$xml
=
new
SimpleXMLElement
(
'<?xml version="1.0" encoding="utf-8" ?><translations '
.
$this
->
array2values
(
$arr
[
'@attributes'
])
.
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></translations>'
);
foreach
(
$arr
[
'attribute'
]
AS
$key
=>
$value
)
{
$ch
=
$xml
->
addChild
(
'attribute'
);
$ch
->
addAttribute
(
'id'
,
$value
[
'@attributes'
][
'id'
]);
$ch
->
addChild
(
'name'
,
$value
[
'name'
]);
$ch
->
addChild
(
'translation'
,
$value
[
'translation'
]);
$ch2
=
$ch
->
addChild
(
'values'
);
if
(
is_array
(
$value
[
'values'
][
'value'
]))
{
foreach
(
$value
[
'values'
][
'value'
]
AS
$values
)
{
$ch3
=
$ch2
->
addChild
(
'value'
);
if
(
is_array
(
$values
))
{
foreach
(
$values
AS
$k
=>
$v
)
{
$ch3
->
{
$k
}
=
$v
;
}
}
}
}
}
$dom
=
dom_import_simplexml
(
$xml
)
->
ownerDocument
;
$dom
->
formatOutput
=
true
;
return
$dom
->
saveXML
();
}
}
$errors
=
array
();
if
(
isset
(
$_POST
[
'post'
])
&&
$_POST
[
'post'
]
==
1
)
{
if
(
isset
(
$_FILES
[
'sourceFile'
])
&&
isset
(
$_FILES
[
'translationFile'
])
&&
$_FILES
[
'sourceFile'
][
'error'
]
==
0
&&
$_FILES
[
'translationFile'
][
'error'
]
==
0
)
{
$sourceFile
=
file_get_contents
(
$_FILES
[
'sourceFile'
][
'tmp_name'
]);
$translationFile
=
file_get_contents
(
$_FILES
[
'translationFile'
][
'tmp_name'
]);
$merger
=
new
merger
(
$sourceFile
,
$translationFile
);
$xml
=
$merger
->
getXml
();
header
(
'Content-disposition: attachment; filename="newfile.xml"'
);
header
(
'Content-type: "text/xml"; charset="utf8"'
);
header
(
"Content-Length: "
.
strlen
(
$xml
));
echo
$xml
;
exit
();
}
else
{
$errors
[]
=
'Nebyly odeslány žádné soubory'
;
}
}
?>
<html>
<head>
<title>
XML translation files merger
</title>
<meta
charset=
"UTF-8"
/>
<!-- Latest compiled and minified CSS -->
<link
rel=
"stylesheet"
href=
"//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"
>
<!-- Optional theme -->
<link
rel=
"stylesheet"
href=
"//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"
>
<!-- Latest compiled and minified JavaScript -->
<script
src=
"//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"
></script>
<style>
body
{
padding-top
:
40px
;
padding-bottom
:
40px
;
background-color
:
#eee
;
}
form
{
max-width
:
490px
;
padding
:
15px
;
margin
:
0
auto
;
}
</style>
</head>
<body>
<div
class=
"container"
>
<?php
foreach
(
$errors
AS
$error
)
{
echo
'<div class="alert alert-danger">'
.
$error
.
'</div>'
;
}
?>
<form
method=
"post"
action=
""
enctype=
"multipart/form-data"
>
<input
type=
"hidden"
value=
"1"
name=
"post"
/>
<table>
<tr>
<th>
Zdrojový soubor:
</th>
<td>
<input
type=
"file"
name=
"sourceFile"
class=
"form-control"
/>
</td>
</tr>
<tr>
<th>
Překladový soubor:
</th>
<td>
<input
type=
"file"
name=
"translationFile"
class=
"form-control"
/>
</td>
</tr>
<tr>
<td
colspan=
"2"
>
<input
type=
"submit"
class=
"btn btn-lg btn-primary btn-block"
name=
"Spojit"
/>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment