Jump to content

API: How to Find All Files/Texdomains Listed as "Translation files exist" in the Admin?


bytesource
 Share

Recommended Posts

Hi, 

I want to retrieve via the API all translation files for /site/ that I manually selected on the page /admin/setup/language-translator/add/ (please see the attached screenshot). I do not want the JSON files, I only need the textdomain representation of each of these files, so that I can call methods of the LanguageTranslator class class on them. 

The problem is I am not sure how the manually selected texdomains are distinguished from all other textdomains, so I am not quite sure how to approach this problem. 

Just for reference, below is the code I wrote for retrieving all untranslated text strings from a single textdomain. Now I want to do this for all textdomains/files that I selected a described above.

// $filename: path from site root to file to be parsed
// $translator: instace of LanguageTranslator for target language
// returns array(hash => array(textdomain, text, comment), ...)
function getUntranslatedStaticFromTextdomain($filename, LanguageTranslator $translator) {

$parser = new LanguageParser($translator, $filename);
$realUntranslated = array(); 
$comments = $parser->getComments();

// Note: getUntranslated() returns ALL phrases (in the default language),
//       even if already translated.
// So we need to filter out all translated phrases.
foreach ($parser->getUntranslated() as $hash => $originalText) {
        $textdomain  = $translator->filenameToTextdomain($filename);
        $tdObject    = $translator->getTextdomain($textdomain);
        // if no translation is present, has is not set.
   $hasTranslation = isset($tdObject['translations'][$hash]['text']);

   if(!$hasTranslation) {  
      $comment = isset($comments[$hash]) ? $comments[$hash] : "";
      $realUntranslated[$hash] = array(
         'textdomain' => $textdomain, 
         'text'       => $originalText, 
         'comment'    => $comment
      );
   }
}
return $realUntranslated;
}

Maybe someone has done this before and could point me into the right direction.

Cheers, 

Stefan

post-855-0-48153300-1426754136_thumb.png

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...