static @Nullable Locale parseLocale(final @NotNull String string) {
    final String[] segments = string.split("_", 3); // language_country_variant
    final int length = segments.length;
    if (length == 1) {
      return new Locale(string); // language
    } else if (length == 2) {
      return new Locale(segments[0], segments[1]); // language + country
    } else if (length == 3) {
      return new Locale(segments[0], segments[1], segments[2]); // language + country + variant
    }
    return null;
  }
Parses a {@link Locale} from a {@link String}.

@param string the string
@return a locale
@since 4.0.0
api/src/main/java/net/kyori/adventure/translation/Translator.java