Jump to content

Any tips on expoting/importing site content translations?


cream
 Share

Recommended Posts

Hi all,

We have this huge website (over 7000 pages and a few dozen templates). We've used TextLanguage and TextAreaLanguage fields for all textual fields, and all image and file fields have their own description input boxes for different languages too.

Now we'd need to export all pages and send them to our translator so they can translate all site contents with their specialized programs, and a way to import the translations back to our site alongside the content in original language.

Has anyone done anything similar to this? How did you solve it? Maybe there already is a solid way to do this, or an idea we've not thought of yet. Thanks for any thoughts!

Link to comment
Share on other sites

Does the translation system import which file type? json, xml, csv?

You can export all the pages' contents to one of these formats and import them again after that. The only thing that will make it more or less hard is the 3rd party system.

Link to comment
Share on other sites

Hi! The translator sent us a huge list of file formats their software's exports and imports supports, including json, xml, csv and even html. So it won't be a problem.

Do you have an example on how to go about exporting from and importing to ProcessWire again? Some module perhaps? I've tried adrian's awesome Batch Child Editor, but it doesn't seem to support multi-language fields.

Link to comment
Share on other sites

Great!

Oh yeah, there's a lot of examples here. Have in mind that importing different languages if just a matter of setting the language before importing the content, nothing more. :)

Let's see, to begin, there's Ryan great case study on importing content from Wordpress

And an example of mine, where I show how to import book contents in two languages (en and pt):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Import Books</title>
</head>
<body>
  <table border='1' width='100%'>
  <thead>
    <tr>      
      <th>ID</th>
      <th>Title</th>      
    </tr>
</thead>
<tbody>
<?php
 
// get access to WordPress wpautop() function
//include("./wordpress/wp-includes/formatting.php"); 
 
$wpdb = new PDO("mysql:dbname=ricardo-wp4_db;host=localhost", "root", "root", 
  array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
 
$books = wire('pages')->get('/books/');
 
$sql = "
  SELECT * FROM wp_pods_books
  ";
 
$query = $wpdb->prepare($sql);
$query->execute();

while($row = $query->fetch(PDO::FETCH_ASSOC)) {
  
  $book = $books->child("wpid=$row[id]"); // do we already have this book?
  
  if(!$book->id) {
    // create a new post
    $book = new Page();
    $book->template = 'book';
    $book->parent = $books;
    echo "Creating new book...\n";
  }
 
  
  $book->of(false);
  $book->wpid = $row['id'];
  $book->name = wire('sanitizer')->pageName($row['name'], true);
  

  $en = $languages->get("default");
  $book->title->setLanguageValue($en, $row['name']);
  $book->body->setLanguageValue($en, $row['body']); 
  $book->introduction->setLanguageValue($en, $row['intro']); 
  //add more fields if needed

  $pt = $languages->get("pt");
  $book->title->setLanguageValue($pt, $row['name_pt']);
  $book->body->setLanguageValue($pt, $markdown->convert($row['body_pt']));
  $book->introduction->setLanguageValue($pt, $markdown->convert($row['intro']));
  
  //We need to activate portuguese page so it will appear on the front-end
  $book->set("status$pt", 1);

 
  // give detailed report about this post
  echo "<tr>" .       
       "<td>$row[id]</td>" .
       "<td>$book->title</td>" .       
       "</tr>";
 
  $book->save();
 
}

?>
</tbody>
</table>
</body>
</html>

You can get the gist here.

And last but no least, there's Adrian's Migrator module -> https://processwire.com/talk/topic/8660-migrator/?hl=migrator

Edited by Sérgio
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

I've done something similar a few years ago. Unfortunately I don't have the code anymore. From my vague recollection I've done the export this way:

I built an array with all templates which contain translateable fields and the translateable fields. With this informations I built a foreach loop which loops over the the templates and writes the contents of the fields in csv-files.

The import was done the same way but only the other directions ;-)

The translators could do so the translations of 6 languages and got no access to the backend.

I hope I could give you a helpful tip.

Edit: I can remind me that we had done this with 6 independent branches without textLanguage fields. If you want to get the values you have to switch the user language for the languages to get the right values. This must also be done in the case you want to import the values. In an other project I had also to import a huge collection of values from 2 languages. If you have further questions don't hesitate ;-)

Edited by hheyne
  • Like 1
Link to comment
Share on other sites

Just curious: Why can't these translators simply do their work directly in PW?

so they can translate all site contents with their specialized programs

What "spezialized programs"? imho, a professional translator should be capable to deal with various standard industry solutions such as Microsoft / OpenOffice products, or Adobe / CMS backend / WYSIWYG interfaces.

Link to comment
Share on other sites

If I remember that correctly some of the clients I'm working for are using specialized translation software, as lot's of the marketing speech is already translated somewhere, especially company specific terms and phrases. And I doubt that someone is supposed to translate those 7000 pages of tkaranka fully by hand.

  • Like 1
Link to comment
Share on other sites

Wow, what a nice surprice to come back to office after the weekend and find so detailed answers!

@Sérgio

This code sample and the notion of just changing the language are invaluable. I should have guessed the simplicity, this being ProcessWire after all... Next I shall read Ryan's case study (which I believe will be enlightening!) and check adrian's Migration module in light of this. Thank you for pointing these!

@hheyne

Thanks for this recolletion! It sure helps me to grasp the way of thought, and proves it's not a big deal after all.

@dragan

As LostKobrakai already answered, they use a program that has a kind of memory of commonly used phrases and translations for certain words for a brand, so that everything stays in line and reduces the actual translating work tremendously. For starters. It's quite fascinating really, here's a link to an overview of the technologies if you're interested: http://maris.fi/en/faq/translation-memory/

It would also be irrational way to use time customer is paying by clicking through the admin interface and try to cover every single page, tab and field individually and with no way to see the whole context at a glance. This is not a small site we're talking about here after all.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...