get('php-censor.basic.language', null); if (self::setLanguage($language)) { return; } // Fall back to English: self::$language = 'en'; self::$strings = self::loadLanguage(); } /** * Load a specific language file. * * @param string $language * * @return string[]|null */ protected static function loadLanguage($language = null) { $language = $language ? $language : self::$language; $langFile = SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.' . $language . '.php'; if (!file_exists($langFile)) { return null; } $strings = include($langFile); if (is_null($strings) || !is_array($strings) || !count($strings)) { return null; } return $strings; } /** * Load the names of all available languages. */ protected static function loadAvailableLanguages() { $matches = []; foreach (glob(SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.*.php') as $file) { if (preg_match('/lang\.([a-z]{2}\-?[a-z]*)\.php/', $file, $matches)) { self::$languages[] = $matches[1]; } } } /** * Create a time tag for localization. * * See http://momentjs.com/docs/#/displaying/format/ for a list of supported formats. * * @param \DateTime $dateTime The dateTime to represent. * @param string $format The moment.js format to use. * * @return string The formatted tag. */ public static function formatDateTime(\DateTime $dateTime, $format = 'lll') { return sprintf( '', $dateTime->format(\DateTime::ISO8601), $format, $dateTime->format(\DateTime::RFC2822) ); } }