Skip to content

Instantly share code, notes, and snippets.

@Rarst
Last active January 4, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rarst/5ad39440fca835d3a981 to your computer and use it in GitHub Desktop.
Save Rarst/5ad39440fca835d3a981 to your computer and use it in GitHub Desktop.
Converter from Facebook's locales XML to PHP array.
{
"name": "yoast/facebook-util",
"require": {
"symfony/dom-crawler": "^2.6",
"symfony/css-selector": "^2.6"
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
// from https://www.facebook.com/translations/FacebookLocales.xml
$xml = file_get_contents( __DIR__ . '/FacebookLocales.xml' );
$crawler = new \Symfony\Component\DomCrawler\Crawler();
$crawler->addXmlContent( $xml );
$locales = $crawler->filter( 'locale' );
$output = "array(\n";
foreach ($locales as $locale) {
$locale = new \Symfony\Component\DomCrawler\Crawler( $locale );
$representation = $locale->filter( 'representation' )->text();
$name = $locale->filterXPath( '//englishName' )->text();
$output .= "\t'{$representation}', // {$name}.\n";
}
$output .= ");";
echo $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment