Child pages
  • File import: writing importer
Skip to end of metadata
Go to start of metadata

Writing your own importer

oTranCe allows to import existing language files into the system. Therefore, it needs to analyse the uploaded or pasted data and extract key-value pairs from it. The application already includes importers for common file structures like PHP-Arrays, CSV, OXID, Redaxo and Titanium.

If your current project language files are not covered by these ready-to-use importers you can build one by yourself, following this steps:

Creating necessary files

2 files need to be present:

  • modules/library/Import/MyNewImporter.php
  • modules/library/Import/views/mynewimporter.phtml

The class file at modules/library/Import/MyNewImporter.php contains the logic (you can copy & rename an existing class). The importer class needs to implement the Msd_Import_Interface. It has to have 2 methods:

  • extract($data)
  • getInfo($view)

The getInfo() method simply renders the informational view, that is shown in the GUI when clicking on the i-icon. It should tell the user in which cases this importer can be used and which structure is required. The view is named similar to the importer (lowercase) and must be placed at  modules/library/Import/views.

The extractData() method will get the file or textbox content as a string. It has to extract the key/value pairs and needs to return them as an associative array:

'LANGUAGE_KEY_1' => 'I am the value for language key 1',
'LANGUAGE_KEY_2' => 'Surprise, surprise: I am the value for language key 2',

Please take a look at the existing importers to get an idea how you could achieve this.

That's all.

When these 2 files are present, oTranCe will list them automatically on the import page.

  • No labels