3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TranslationError extends \Exception { public function __construct(string $message){ parent::__construct($message); } } class TranslationUtils { /** * List of strings that are required to be in the translation if they appear in the english one */ private const MANDATORY_MATCHES = ['/…/', '/%(\\d+\$)?(b|B|h|H|s|S|c|C|d|i|x|X|e|E|f|g|G|a|A|t|T|n)/']; public static function checkTranslation(string $original, string $translation){ //CHECK MANDATORY STRINGS foreach(static::MANDATORY_MATCHES as $pattern){ $matches = []; if(preg_match_all($pattern, $original, $matches) >= 1){ foreach($matches[0] as $match){ if(strpos($translation, $match) === FALSE){ throw new TranslationError("Missing '" . $match . "' from translation!"); } } } } } public static function isTranslationOk(string $original, string $translation) : bool { try { TranslationUtils::checkTranslation("Loading…", "adsda..."); return true; } catch(TranslationError $ex){ var_dump($ex->getMessage()); return false; } } } var_dump(TranslationUtils::isTranslationOk("Loading…", "adsda...")); var_dump(TranslationUtils::isTranslationOk("Loading…", "adsda…")); var_dump(TranslationUtils::isTranslationOk("Ciao %s", "Ciao %s")); var_dump(TranslationUtils::isTranslationOk("NOPE %d", "YES %s")); var_dump(TranslationUtils::isTranslationOk("Allo %\$1s", "Hello %\$1s %\$2s")); var_dump(TranslationUtils::isTranslationOk("Loading…", "adsda...")); var_dump(TranslationUtils::isTranslationOk("Loading…", "adsda...")); var_dump(TranslationUtils::isTranslationOk("Loading…", "adsda..."));
Output for git.master, git.master_jit, rfc.property-hooks
string(31) "Missing '…' from translation!" bool(false) string(31) "Missing '…' from translation!" bool(false) string(31) "Missing '…' from translation!" bool(false) string(31) "Missing '…' from translation!" bool(false) string(31) "Missing '…' from translation!" bool(false) string(31) "Missing '…' from translation!" bool(false) string(31) "Missing '…' from translation!" bool(false) string(31) "Missing '…' from translation!" bool(false)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.48 ms | 402 KiB | 8 Q