warren-bank / node-translate-android-strings

Command-line utility to use the IBM Watson Language Translator service to translate Android 'strings.xml'.
GNU General Public License v2.0
2 stars 0 forks source link

is possible use your app for translate to fr, de and it this xml file? #1

Closed johnfelipe closed 2 years ago

johnfelipe commented 2 years ago

https://github.com/statisticssweden/PxWeb/blob/master/PXWeb/Resources/Languages/pxlang.xml

johnfelipe commented 2 years ago

i put command like this

root@ubuntu20virgeninwindows:~/node-translate-android-strings# npm install --global @warren-bank/translate-android-strings

added 3 packages, and audited 4 packages in 5s

found 0 vulnerabilities

and this

root@ubuntu20virgeninwindows:~/node-translate-android-strings# translate-android-strings -i 'en' -o 'de' -o 'es' -o 'fr' -f '/root/node-translate-android-strings/PxWeb/PXWeb/Resources/Languages/pxlang.xml' -d '/root/node-translate-android-strings/PxWeb/PXWeb/Resources/Languages/translations' --apiKey AEF-blablablabla-55sZ-blablablbablabal --apiUrl https://api.us-south.language-translator.watson.cloud.ibm.com/instances/blablablbablabal -40a6-4ac3-8324-blablablbablabal 
ERROR: IBM Cloud account API key is required

how solve this?

warren-bank commented 2 years ago

incorrect cli options:

"-k" <key>
"--api-key" <key>
    [optional] IBM Cloud account API key.
    Default: Value is read from "IBM_TRANSLATOR_API_KEY" environment variable.

"-u" <url>
"--api-url" <url>
    [optional] IBM Cloud account API URL.
    Default: Value is read from "IBM_TRANSLATOR_API_URL" environment variable.

in your command-line, replace:

probably won't matter, but I'd put quotes around the values.. to be on the safe side.

warren-bank commented 2 years ago

oh geesh..

ok, so i just took a quick peek at your input xml file.. and see that even after you configure your IBM account properly.. this tool won't work for you anyway.. because your input xml file isn't an Android resource strings xml file.. which is the format this tool is made to process.

Having said that.. if you're so inclined.. it should be fairly simple to modify the tool to correctly process this input format.. since this format is very simple.. and (if memory serves) this would only require updating a regex pattern.

johnfelipe commented 2 years ago

Can u give me a little section formatted In correct way I will create a regex for change my format and try.

El mié, 3 de ago. de 2022, 12:03 p. m., Warren Bank < @.***> escribió:

oh geesh..

ok, so i just took a quick peek at your input xml file.. and see that even after you configure your IBM account properly.. this tool won't work for you anyway.. because your input xml file isn't an Android resource strings xml file.. which is the format this tool is made to process.

— Reply to this email directly, view it on GitHub https://github.com/warren-bank/node-translate-android-strings/issues/1#issuecomment-1204236007, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADIWFDWBUV4V33UC4ZK45LVXKQ67ANCNFSM55OVZAPQ . You are receiving this because you authored the thread.Message ID: @.*** com>

warren-bank commented 2 years ago

give me a sec.. I need to look at the code to refresh my memory.. I haven't touched this repo in a while..

warren-bank commented 2 years ago

try editing this: one line

change from:

"string":   /\<string([^\>]+)\>(.+?)\<\/string\>/ig,

to:

"string":   /\<(sentence)[^\>]+\bvalue="([^"]+)"[^\>]*\/\>/ig,

here is a super quick test to validate the regex will match:

{
  const regex   = /\<(sentence)[^\>]+\bvalue="([^"]+)"[^\>]*\/\>/ig
  const line    = `   <sentence name="CtrlChangeTextsText" value="Make your text changes and press 'Continue'"/>   `
  const matches = regex.exec(line)

  console.log({xml_attributes: matches[1], value: matches[2]})
}
warren-bank commented 2 years ago

notes:

fyi:

johnfelipe commented 2 years ago

No, no Pls give me an example of my file, a section with 5 lines, convert 5 lines of mi files for extact version of files allowed in your translator. Tnks

El mié, 3 de ago. de 2022, 12:31 p. m., Warren Bank < @.***> escribió:

notes:

  • the first capture group does nothing.. it's simply to provide some substring as "xml_attributes" for the code that later uses this substring to test whether or not it contains translatable="false"
    • since you want all lines to be translatable, a static value that doesn't match this test is used

— Reply to this email directly, view it on GitHub https://github.com/warren-bank/node-translate-android-strings/issues/1#issuecomment-1204267022, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADIWFA24DTZY2IWDFY4V63VXKUIXANCNFSM55OVZAPQ . You are receiving this because you authored the thread.Message ID: @.*** com>