Last active
January 4, 2016 15:00
-
-
Save Rarst/5ad39440fca835d3a981 to your computer and use it in GitHub Desktop.
Converter from Facebook's locales XML to PHP array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "yoast/facebook-util", | |
"require": { | |
"symfony/dom-crawler": "^2.6", | |
"symfony/css-selector": "^2.6" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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