Yasumi\Translations::addTranslation PHP Method

addTranslation() public method

Adds translation for holiday in specific locale.
public addTranslation ( string $shortName, string $locale, string $translation )
$shortName string holiday short name
$locale string locale
$translation string translation
    public function addTranslation($shortName, $locale, $translation)
    {
        $this->isValidLocale($locale);
        // Validate the given locale
        if (!array_key_exists($shortName, $this->translations)) {
            $this->translations[$shortName] = [];
        }
        $this->translations[$shortName][$locale] = $translation;
    }

Usage Example

示例#1
0
 /**
  * Tests that no translation is returned for not translated locale.
  */
 public function testNoTranslationForNotTranslatedLocale()
 {
     $translations = new Translations($this->locales);
     $locale = 'en_US';
     $shortName = 'newYearsDay';
     $translation = 'New Year\'s Day';
     $unknownLocale = 'pl_PL';
     $translations->addTranslation($shortName, $locale, $translation);
     $this->assertNull($translations->getTranslation($shortName, $unknownLocale));
 }