Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
b7df0faa
Commit
b7df0faa
authored
14 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
Enhance autotranslator to update lang files before a release.
parent
5747e63c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dev/translation/autotranslator.php
+12
-8
12 additions, 8 deletions
dev/translation/autotranslator.php
dev/translation/langAutoParser.class.php
+55
-25
55 additions, 25 deletions
dev/translation/langAutoParser.class.php
with
67 additions
and
33 deletions
dev/translation/autotranslator.php
+
12
−
8
View file @
b7df0faa
...
...
@@ -31,12 +31,13 @@ $path=dirname(__FILE__).'/';
// Test if batch mode
if
(
substr
(
$sapi_type
,
0
,
3
)
==
'cgi'
)
{
echo
"Error: You ar using
r
PH for CGI. To execute "
.
$script_file
.
" from command line, you must use PHP for CLI mode.
\n
"
;
echo
"Error: You ar
e
using PH
P
for CGI. To execute "
.
$script_file
.
" from command line, you must use PHP for CLI mode.
\n
"
;
exit
;
}
// Include Dolibarr environment
require_once
(
$path
.
"../../htdocs/master.inc.php"
);
require_once
(
$path
.
"../../htdocs/lib/files.lib.php"
);
// After this $db is an opened handler to database. We close it at end of file.
// Load main language strings
...
...
@@ -54,7 +55,7 @@ $dir=DOL_DOCUMENT_ROOT."/langs";
// Check parameters
if
(
!
isset
(
$argv
[
2
]))
{
print
"Usage: "
.
$script_file
.
" lang_code_src lang_code_dest [langfile.lang]
\n
"
;
print
"Usage: "
.
$script_file
.
" lang_code_src lang_code_dest
|all
[langfile.lang]
\n
"
;
print
"Example: "
.
$script_file
.
" en_US pt_PT
\n
"
;
print
"Rem: lang_code to use can be found on http://www.google.com/language_tools
\n
"
;
exit
;
...
...
@@ -71,14 +72,17 @@ if (isset($argv[3]))
}
print
'Files will be generated/updated in directory '
.
$dir
.
"
\n
"
;
if
(
!
is_dir
(
$dir
.
'/'
.
$argv
[
2
])
)
if
(
$argv
[
2
]
!=
'all'
)
{
print
'Create directory '
.
$dir
.
'/'
.
$argv
[
2
]
.
"
\n
"
;
$result
=
mkdir
(
$dir
.
'/'
.
$argv
[
2
]);
if
(
!
$result
)
if
(
!
is_dir
(
$dir
.
'/'
.
$argv
[
2
]))
{
$db
->
close
();
return
-
1
;
print
'Create directory '
.
$dir
.
'/'
.
$argv
[
2
]
.
"
\n
"
;
$result
=
mkdir
(
$dir
.
'/'
.
$argv
[
2
]);
if
(
!
$result
)
{
$db
->
close
();
return
-
1
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
dev/translation/langAutoParser.class.php
+
55
−
25
View file @
b7df0faa
...
...
@@ -50,34 +50,64 @@ class langAutoParser {
$fileContent
=
null
;
$this
->
translatedFiles
=
array
();
$refPath
=
$this
->
langDir
.
$this
->
refLang
.
self
::
DIR_SEPARATOR
.
$file
;
$destPath
=
$this
->
langDir
.
$this
->
destLang
.
self
::
DIR_SEPARATOR
.
$file
;
$fileContent
=
file
(
$refPath
,
FILE_IGNORE_NEW_LINES
|
FILE_SKIP_EMPTY_LINES
);
$fileContent
=
file
(
$refPath
,
FILE_IGNORE_NEW_LINES
|
FILE_SKIP_EMPTY_LINES
);
print
"Processing file "
.
$file
.
", with "
.
sizeof
(
$fileContent
)
.
" lines<br>
\n
"
;
// Check destination file presence
if
(
!
file_exists
(
$destPath
)
){
// No file presente generate file
echo
"File not found: "
.
$file
.
"<br>
\n
"
;
echo
"Generating file "
.
$file
.
"<br>
\n
"
;
$this
->
createTranslationFile
(
$destPath
);
}
// Translate lines
$fileContentDest
=
file
(
$destPath
,
FILE_IGNORE_NEW_LINES
|
FILE_SKIP_EMPTY_LINES
);
$newlines
=
0
;
foreach
(
$fileContent
as
$line
){
$key
=
$this
->
getLineKey
(
$line
);
$value
=
$this
->
getLineValue
(
$line
);
if
(
$key
&&
$value
)
// Define target dirs
$targetlangs
=
array
(
$this
->
destLang
);
if
(
$this
->
destLang
==
'all'
)
{
$targetlangs
=
array
();
// If we must process all languages
$arraytmp
=
dol_dir_list
(
$this
->
langDir
,
'directories'
,
0
);
foreach
(
$arraytmp
as
$dirtmp
)
{
$newlines
+=
$this
->
translateFileLine
(
$fileContentDest
,
$file
,
$key
,
$value
);
if
(
$dirtmp
[
'name'
]
===
$this
->
refLang
)
continue
;
// We discard source language
if
(
preg_match
(
'/^en/i'
,
$dirtmp
[
'name'
]))
continue
;
// We discard en_* languages
if
(
preg_match
(
'/^fr/i'
,
$dirtmp
[
'name'
]))
continue
;
// We discard fr_* languages
if
(
preg_match
(
'/^es/i'
,
$dirtmp
[
'name'
]))
continue
;
// We discard es_* languages
if
(
preg_match
(
'/es_CA/i'
,
$dirtmp
[
'name'
]))
continue
;
// We discard es_CA language
if
(
preg_match
(
'/^\./i'
,
$dirtmp
[
'name'
]))
continue
;
// We discard files .*
if
(
preg_match
(
'/^CVS/i'
,
$dirtmp
[
'name'
]))
continue
;
// We discard CVS
$targetlangs
[]
=
$dirtmp
[
'name'
];
}
//var_dump($targetlangs);
}
$this
->
updateTranslationFile
(
$destPath
,
$file
);
echo
"New translated lines: "
.
$newlines
.
"<br>
\n
"
;
$this
->
time_end
=
date
(
'Y-m-d H:i:s'
);
#if ($counter ==3) die('fim');
// Process translation of source file for each target languages
foreach
(
$targetlangs
as
$mydestLang
)
{
$destPath
=
$this
->
langDir
.
$mydestLang
.
self
::
DIR_SEPARATOR
.
$file
;
// Check destination file presence
if
(
!
file_exists
(
$destPath
)
){
// No file present, we generate file
echo
"File not found: "
.
$destPath
.
". We generate it.<br>
\n
"
;
$this
->
createTranslationFile
(
$destPath
,
$mydestLang
);
}
else
{
echo
"Updating file: "
.
$destPath
.
"<br>
\n
"
;
}
// Translate lines
$fileContentDest
=
file
(
$destPath
,
FILE_IGNORE_NEW_LINES
|
FILE_SKIP_EMPTY_LINES
);
$newlines
=
0
;
foreach
(
$fileContent
as
$line
){
$key
=
$this
->
getLineKey
(
$line
);
$value
=
$this
->
getLineValue
(
$line
);
if
(
$key
&&
$value
)
{
$newlines
+=
$this
->
translateFileLine
(
$fileContentDest
,
$file
,
$key
,
$value
);
}
}
$this
->
updateTranslationFile
(
$destPath
,
$file
);
echo
"New translated lines: "
.
$newlines
.
"<br>
\n
"
;
$this
->
time_end
=
date
(
'Y-m-d H:i:s'
);
#if ($counter ==3) die('fim');
}
}
}
...
...
@@ -99,10 +129,10 @@ FILE_SKIP_EMPTY_LINES);
return
;
}
private
function
createTranslationFile
(
$path
){
private
function
createTranslationFile
(
$path
,
$mydestlang
){
$fp
=
fopen
(
$path
,
'w+'
);
fwrite
(
$fp
,
"/*
\r\n
"
);
fwrite
(
$fp
,
" * Language code:
{
$
this
->
dest
L
ang
}
\r\n
"
);
fwrite
(
$fp
,
" * Language code:
{
$
my
dest
l
ang
}
\r\n
"
);
fwrite
(
$fp
,
" * Automatic generated via autotranslator.php tool
\r\n
"
);
fwrite
(
$fp
,
" * Generation date "
.
$this
->
time
.
"
\r\n
"
);
fwrite
(
$fp
,
" */
\r\n
"
);
...
...
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