0

Hello I am trying to doing some translation on an xml file with open ai.

I am working with PHP, I have my script below:

$document = file_get_contents('#####.xml');

$prompt = "translate this document into $language:\n\n" . $document;

    $response = $openai->completions()->create([
        'model' => 'text-davinci-003',
        'prompt' => $prompt,
        'temperature' => 0.5,
        'max_tokens' => 1024,
        'n' => 1,
        'stop' => '\n\n',
    ]);

    // Extract the translated text from the API response
    $translatedText = $response['choices'][0]['text'];

    // Convert the translated text back to XML or JSON format
    $translatedDocument = $translatedText; // Replace this with your own conversion code

    // Save the translated document to a file
    $filename = "########.xml";
    
    file_put_contents($filename, $translatedDocument);

this is a sample of the content of the xml file:

<?xml version="1.0" encoding="UTF-8"?>
<page text_nodes="0" filename="home" url="home" id="336760838" language="default">
  <name>Home</name>
  <tags>
    <tag id="e217a308-5401-4c08-8283-ba24340e6051:button:size" type="STRING">
      <text>
        <![CDATA[large]]>
      </text>
    </tag>
 </tags>
</page>

I only want to translate whatever content is in:

 <![CDATA[large]]>. e.g large

 <![CDATA[the boy is good]]>. e.g the boy is good

How do I translate this specifically

tee
  • 31
  • 5

0 Answers0