Returns a localised list of all country names, sorted by localised name.

@param bool $returnall return all or just enabled
@param string $lang moodle translation language, null means use current
@return array two-letter country code => translated name.
482349
public function get_list_of_countries($returnall = false, $lang = null) {
        global $CFG;

        if ($lang === null) {
            $lang = current_language();
        }

        $countries = $this->load_component_strings('core_countries', $lang);
        core_collator::asort($countries);
        if (!$returnall and !empty($CFG->allcountrycodes)) {
            $enabled = explode(',', $CFG->allcountrycodes);
            $return = array();
            foreach ($enabled as $c) {
                if (isset($countries[$c])) {
                    $return[$c] = $countries[$c];
                }
            }
            return $return;
        }

        return $countries;
    }
244883
public function getTranslation($lang, $create = false)
    {
        foreach ($this->translations as $translation) {
            if ($lang == $translation->getLang()) {
                return $translation;
            }
        }

        if ($create) {
            $class = $this->getTranslationClass();

            /** @var TranslationInterface $translation */
            $translation = new $class();
            $translation->setLang($lang);
            $this->addTranslation($translation);

            return $translation;
        }

        return null;
    }
963894
public function getList($country)
    {
        $list = Region::get()
            ->filter("CountryCode", strtoupper($country));

        if (!$list->exists() && $this->getCreateEmptyDefault()) {
            $countries = i18n::getData()->getCountries();
            if (isset($countries[strtolower($country)])) {
                $name = $countries[strtolower($country)];
            } else {
                $name = $country;
            }
            $list = ArrayList::create();
            $list->push(Region::create([
                "Name" => $name,
                "Type" => "Nation",
                "Code" => strtoupper($country),
                "CountryCode" => strtoupper($country)
            ]));
        }

        return $list;
    }
1199654
public static function GetLocale($lang)
	{
		if (array_key_exists($lang, LocaleFactory::$_locales))
			return LocaleFactory::$_locales[$lang];
		
		$locale = new CultureInfo($lang);

		LocaleFactory::$_locales[$lang] = $locale;

		return $locale;
	}
325199
private function getTranslations($lang) {
    if (!isset($this->translations[$lang])) {
      $messageFile = $this->localeDir."/messages_".$lang.".php";
      if (file_exists($messageFile)) {
        require_once($messageFile);
        // store for later reference
        $this->translations[$lang] = ${"messages_$lang"};
      }
      else {
        $this->translations[$lang] = [];
      }
    }
    return $this->translations[$lang];
  }
78103
public function getLangName( $lang = false ) {
		$lang = $lang ? $this->normalizeLang( $lang ) : $this->getLang();
		return $this->getLangNames()[$lang] ?? '';
	}
261566
public static function get_component_strings($component, $lang = null) {

        if (empty($lang)) {
            $lang = current_language();
        }

        $params = self::validate_parameters(self::get_component_strings_parameters(),
                      array('component'=>$component, 'lang' => $lang));

        $stringmanager = get_string_manager();

        $wsstrings = array();
        $componentstrings = $stringmanager->load_component_strings($params['component'], $params['lang']);
        foreach($componentstrings as $stringid => $string) {
            $wsstring = array();
            $wsstring['stringid'] = $stringid;
            $wsstring['string'] = $string;
            $wsstrings[] = $wsstring;
        }

        return $wsstrings;
    }
438178
protected function split_lang($lang)
	{
		if ( ! isset($this->_fallback_paths[$lang]))
		{
			$splits = array();
			$lang_parts = explode('-', $lang);
			while ($lang_parts)
			{
				$splits[] = implode('-', $lang_parts);
				array_pop($lang_parts);
			}
			$this->_fallback_paths[$lang] = $splits;
		}
		return $this->_fallback_paths[$lang];
	}
79960
public function transform($lang)
    {
        $lang = $this->entityToArray(Lang::class, $lang);
        return [
            'code'      => $lang['code'],
            'i18n'      => $lang['i18n'],
            'isEnabled' => (bool) $lang['is_enabled'],
            'isDefault' => (bool) $lang['is_default'],
        ];
    }
1021056
public function loadLanguages()
    {
        $languages = $this->languageHandler->loadAll();

        $returnArray = array();
        foreach ($languages as $language) {
            $returnArray[] = $this->buildDomainObject($language);
        }

        return $returnArray;
    }
58739
public function getTranslatedProperties(core_kernel_classes_Resource $instance, $lang)
    {
        $returnValue = array();

        try {
            foreach ($instance->getTypes() as $clazz) {
                foreach ($clazz->getProperties(true) as $property) {
                    if ($property->isLgDependent() || $property->getUri() == OntologyRdfs::RDFS_LABEL) {
                        $collection = $instance->getPropertyValuesByLg($property, $lang);
                        if ($collection->count() > 0) {
                            if ($collection->count() == 1) {
                                $returnValue[$property->getUri()] = (string)$collection->get(0);
                            } else {
                                $propData = array();
                                foreach ($collection->getIterator() as $collectionItem) {
                                    $propData[] = (string)$collectionItem;
                                }
                                $returnValue[$property->getUri()] = $propData;
                            }
                        }
                    }
                }
            }
        } catch (\Exception $e) {
            print $e;
        }

        return (array) $returnValue;
    }
1267842
public function getLangFallbacks( $lang ) {
		if ( self::$fallbackCache === null ) {
			// Lazy-initialize
			self::$fallbackCache = $this->fetchLangFallbacks();
		}

		$lang = $this->normalizeLang( $lang );
		return isset( self::$fallbackCache[$lang] ) ? self::$fallbackCache[$lang] : [ 'en' ];
	}
705319
private function getIso3166Countries(): array
    {
        $countries = $this->country_service->getAllCountries();

        // Get the country names for each language
        $country_to_iso3166 = [];

        foreach (I18N::activeLocales() as $locale) {
            I18N::init($locale->languageTag());

            foreach ($this->country_service->iso3166() as $three => $two) {
                $country_to_iso3166[$three]             = $two;
                $country_to_iso3166[$countries[$three]] = $two;
            }
        }

        return $country_to_iso3166;
    }
950553
protected function getActiveLangList()
    {
        if (self::$arActiveLangList !== null || !PluginManager::instance()->hasPlugin('RainLab.Translate')) {
            return self::$arActiveLangList;
        }

        self::$arActiveLangList = \RainLab\Translate\Models\Locale::isEnabled()->lists('code');
        if (empty(self::$arActiveLangList)) {
            return self::$arActiveLangList;
        }

        //Remove default lang from list
        foreach (self::$arActiveLangList as $iKey => $sLangCode) {
            if ($sLangCode == self::$sDefaultLang) {
                unset(self::$arActiveLangList[$iKey]);
                break;
            }
        }

        return self::$arActiveLangList;
    }
1032439
public static function getMetadata($lang)
	{
		$path = self::getLanguagePath(PATH_APP . DS . 'bootstrap' . DS . \App::get('client')->name, $lang);
		$file = $lang . '.xml';

		$result = null;

		if (!is_file("$path/$file"))
		{
			$path = self::getLanguagePath(PATH_CORE . DS . 'bootstrap' . DS . ucfirst(\App::get('client')->name), $lang);
		}

		if (is_file("$path/$file"))
		{
			$result = self::parseXMLLanguageFile("$path/$file");
		}

		if (empty($result))
		{
			return null;
		}

		return $result;
	}
955428
public function getAllLocalizations()
    {
        $localizations = [];
        foreach ($this->getLocalizations() as $child) {
            $localizations[] = $child;
            $localizations = array_merge($localizations, $child->getAllLocalizations());
        }

        return $localizations;
    }
614568
public function children($lang='',$alias=''){
		$collname=$this->collectionName;
		$bitems=$collname::GetInstance();
		$children=$bitems->itemsFilter(array('parent'=>$this->id));
		if(empty($alias)){
			return $children;
			}
		foreach($children as $ch){
			$chalias=$ch->getalias($lang);
			if($chalias==$alias){
				return $ch;
				}
			}
		return NULL;
		}