Skip to content

calin-marian/google-supported-languages

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

google-supported-languages

Languages supported by Google APIs.

Google APIs support a limited list of languages. This library provides a way to validate the language parameter in your own Google API library.

Example code:

  $googleLibrary = new MyAwesomeGoogleApiLibrary($key);
  
  $languageFactory = new \GoogleSupportedLanguages\LanguageFactory();

  $languageCode = 'en';
  $language = $languageFactory->create($languageCode);
  
  $googleLibrary->setLanguage($language);

If the provided language code is not part of the supported list, an InvalidArgumentException is thrown.

Also you can then typehint the parameter to the interface \GoogleSupportedLanguages\Language\LanguageInterface:

  class MyAwesomeGoogleApiLibrary implements MyAwesomeGoogleApiLibraryInterface;
    ....
    public function setLanguage(\GoogleSupportedLanguages\Language\LanguageInterface $language){
      $this->language = $language;
    }
    ....
    public function execute() {
      ...
      $parameters['language'] = $this->language->getCode();
      ....
    }
    ....
  }

Installing the library.

  composer require calin-marian/google-supported-languages