public function test_intersect() { $master = new mlang_component('moodle', 'en', mlang_version::by_branch('MOODLE_18_STABLE')); $master->add_string(new mlang_string('one', 'One')); $master->add_string(new mlang_string('two', 'Two')); $master->add_string(new mlang_string('three', 'Three')); $slave = new mlang_component('moodle', 'cs', mlang_version::by_branch('MOODLE_18_STABLE')); $slave->add_string(new mlang_string('one', 'Jedna')); $slave->add_string(new mlang_string('two', 'Dva')); $slave->add_string(new mlang_string('seven', 'Sedm')); $slave->add_string(new mlang_string('eight', 'Osm')); $slave->intersect($master); $this->assertEqual(2, count($slave->get_string_keys())); $this->assertTrue($slave->has_string('one')); $this->assertTrue($slave->has_string('two')); }
/** * Prunes the strings, keeping just those defined in given $mask as well * * This may be used to get rid of strings that are not defined in another component. * Typically can be used to clean the translation from strings that are not defined in * the master English pack. * Beware - if the string is defined in $mask as deleted, it will be kept in this regardless * its state. * * @param mlang_component $mask master component to compare strings with * @return int number of removed strings */ public function intersect(mlang_component $mask) { $removed = 0; $masked = array_flip($mask->get_string_keys()); foreach (array_keys($this->strings) as $key) { if (!isset($masked[$key])) { $this->unlink_string($key); $removed++; } } return $removed; }