Yasumi\Holiday::mergeGlobalTranslations PHP Method

mergeGlobalTranslations() public method

Merges local translations (preferred) with global translations.
public mergeGlobalTranslations ( yasumi\TranslationsInterface $globalTranslations )
$globalTranslations yasumi\TranslationsInterface global translations
    public function mergeGlobalTranslations(TranslationsInterface $globalTranslations)
    {
        $holidayGlobalTranslations = $globalTranslations->getTranslations($this->shortName);
        $this->translations = array_merge($holidayGlobalTranslations, $this->translations);
    }

Usage Example

Example #1
0
 /**
  * Tests the getName function of the Holiday object with global translations and an overriding custom translation.
  */
 public function testHolidayGetNameWithOverridenGlobalTranslations()
 {
     /** @var TranslationsInterface|PHPUnit_Framework_MockObject_MockObject $translationsStub */
     $translationsStub = $this->getMockBuilder('\\Yasumi\\TranslationsInterface')->getMock();
     $translations = ['en_US' => 'New Year\'s Day', 'pl_PL' => 'Nowy Rok'];
     $translationsStub->expects($this->once())->method('getTranslations')->with($this->equalTo('newYearsDay'))->willReturn($translations);
     $customLocale = 'pl_PL';
     $customTranslation = 'Bardzo Nowy Rok';
     $holiday = new Holiday('newYearsDay', [$customLocale => $customTranslation], new DateTime("2014-01-01"), $customLocale);
     $holiday->mergeGlobalTranslations($translationsStub);
     $this->assertNotNull($holiday->getName());
     $this->assertInternalType('string', $holiday->getName());
     $this->assertEquals($customTranslation, $holiday->getName());
 }
All Usage Examples Of Yasumi\Holiday::mergeGlobalTranslations