Skip to content

Instantly share code, notes, and snippets.

@birkir
Created January 25, 2013 11:40
Show Gist options
  • Save birkir/4633777 to your computer and use it in GitHub Desktop.
Save birkir/4633777 to your computer and use it in GitHub Desktop.
<?php
class Inflector extends Kohana_Inflector {
public static function plural_icelandic($word, $count = NULL)
{
$count = ($count === NULL) ? 0.0 : (float) $count;
if ($count == 1)
return $word;
$url = 'http://mymemory.translated.net/api/get';
$i18n = json_decode(file_get_contents($url.'?q='.rawurlencode($word).'&langpair=is|en'));
if ($i18n->responseStatus == 200 AND isset($i18n->matches[0]->match) AND $i18n->matches[0]->match > 0.8)
{
$word_en = Inflector::plural($i18n->matches[0]->translation, $count);
$i18n = json_decode(file_get_contents($url.'?q='.rawurlencode($word_en).'&langpair=en|is'));
if ($i18n->responseStatus == 200 AND isset($i18n->matches[0]->match) AND $i18n->matches[0]->match > 0.8)
{
$word = UTF8::strtolower($i18n->matches[0]->translation);
}
}
return $word;
}
} // End Inflector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment