getTranslation() public method

Returns translation for holiday in specific locale.
public getTranslation ( string $shortName, string $locale ) : string | null
$shortName string holiday short name
$locale string locale
return string | null translated holiday name
Beispiel #1
0
    /**
     * Tests loading more than one translation file from directory.
     */
    public function testLoadingMultipleTranslationsFromDirectory()
    {
        $firstShortName = 'newYearsDay';
        $firstFileContents = <<<'FILE'
<?php
return [
    'en_US' => 'New Year\'s Day',
    'nl_NL' => 'Nieuwjaar',
    'pl_PL' => 'Nowy Rok',
];
FILE;
        $secondShortName = 'easter';
        $secondFileContents = <<<'FILE'
<?php
return [
    'en_US' => 'Easter Sunday',
    'nl_NL' => 'Eerste Paasdag',
];
FILE;
        vfsStream::setup('root', null, ['lang' => [$firstShortName . '.php' => $firstFileContents, $secondShortName . '.php' => $secondFileContents]]);
        $translations = new Translations($this->locales);
        $translations->loadTranslations(vfsStream::url('root/lang'));
        $locale = 'en_US';
        $translation = 'New Year\'s Day';
        $this->assertNotNull($translations->getTranslations($firstShortName));
        $this->assertNotEmpty($translations->getTranslations($firstShortName));
        $this->assertInternalType('string', $translations->getTranslation($firstShortName, $locale));
        $this->assertEquals($translation, $translations->getTranslation($firstShortName, $locale));
        $locale = 'nl_NL';
        $translation = 'Eerste Paasdag';
        $this->assertNotNull($translations->getTranslations($secondShortName));
        $this->assertNotEmpty($translations->getTranslations($secondShortName));
        $this->assertInternalType('string', $translations->getTranslation($secondShortName, $locale));
        $this->assertEquals($translation, $translations->getTranslation($secondShortName, $locale));
    }