def choose_locale(self, locale: Text) -> Text:
if locale not in self._choice_cache:<EOL><INDENT>locales = self.list_locales()<EOL>best_choice = locales[<NUM_LIT:0>]<EOL>best_level = <NUM_LIT:0><EOL>for candidate in locales:<EOL><INDENT>cmp = compare_locales(locale, candidate)<EOL>if cmp > best_level:<EOL><INDENT>best_choice = candidate<EOL>best_level = cmp<EOL><DEDENT><DEDENT>self._choice_cache[locale] = best_choice<EOL><DEDENT>return self._choice_cache[locale]<EOL>
Returns the best matching locale in what is available.

:param locale: Locale to match
:return: Locale to use