Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 36365df23043
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 79c4618157fd
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 25, 2021

  1. slightly better fallback

    eggrobin committed Dec 25, 2021
    Copy the full SHA
    dcd6346 View commit details
  2. use resolved grammar

    eggrobin committed Dec 25, 2021
    Copy the full SHA
    8cb0045 View commit details
  3. reorder

    eggrobin committed Dec 25, 2021
    Copy the full SHA
    1c59d01 View commit details

Commits on Dec 26, 2021

  1. Merge pull request #3250 from eggrobin/language-fallback

    Ungarble unsupported languages somewhat
    eggrobin authored Dec 26, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    79c4618 View commit details
1 change: 1 addition & 0 deletions ksp_plugin_adapter/localization/en-us.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Localization {
en-us {
#Principia_UILanguage = en-us
// Placeholder-only strings for extracting specific forms.
#Principia_GrammaticalForm_Standalone = <<C:1>>

1 change: 1 addition & 0 deletions ksp_plugin_adapter/localization/fr-fr.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Localization {
fr-fr {
#Principia_UILanguage = fr-fr
// Placeholder-only strings for extracting specific forms.
#Principia_GrammaticalForm_Standalone = <<C:1>>

1 change: 1 addition & 0 deletions ksp_plugin_adapter/localization/zh-cn.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Localization {
zh-cn {
#Principia_UILanguage = zh-cn
#Principia_GrammaticalForm_Standalone = <<C:1>>

// MainWindow
61 changes: 35 additions & 26 deletions ksp_plugin_adapter/localization_extensions.cs
Original file line number Diff line number Diff line change
@@ -35,8 +35,8 @@ public static string StandaloneName(this CelestialBody celestial) {
}

private static bool StartsWithCapitalizedDefiniteArticle(string s) {
return (Localizer.CurrentLanguage == english_us_ && s.StartsWith("The ")) ||
(Localizer.CurrentLanguage == french_ &&
return (UILanguage() == english_us_ && s.StartsWith("The ")) ||
(UILanguage() == french_ &&
(s.StartsWith("La ") || s.StartsWith("Le ")));
}

@@ -92,10 +92,14 @@ private static string Initial(this CelestialBody body) {
: body.Name()[0].ToString();
}

private static string UILanguage() {
return CacheFormat("#Principia_UILanguage");
}

private static string FormatOrNull(string template, params object[] args) {
// Optional translations include the language name so that they do not fall
// back to English.
string qualified_template = $"{template}.{Localizer.CurrentLanguage}";
string qualified_template = $"{template}.{UILanguage()}";
if (!Localizer.Tags.ContainsKey(qualified_template)) {
return null;
}
@@ -119,7 +123,7 @@ public static string CelestialString(string template,
select name).Concat(from arg in args select arg.ToString()).ToArray();
return lru_cache_.Get(template, names,
() => CelestialOverride(template, names, bodies) ??
Localizer.Format(template, names));
Format(template, names));
}

public static string CelestialStringOrNull(string template,
@@ -139,35 +143,40 @@ public static string CacheFormat(string name) {
}

public static string CacheFormat(string name, params string[] args) {
return lru_cache_.Get(name, args, () => Format(name, args));
}

private static string Format(string name, params string[] args) {
// KSP substitutes arguments that are themselves localization keys,
// e.g., the names of the default vessels.
var resolved_args = new List<string>();
foreach (var arg in args) {
// KSP treats nulls as empty strings here (but not in the overload
// that takes objects).
resolved_args.Add(
arg == null ? "" : (Localizer.Tags.GetValueOrNull(arg) ?? arg));
}

// Nested <<>> rules don’t work prior to Lingoona 1.7.0 (2021-07-07).
// We need them for some of the more advanced grammatical constructs.
// We manually replace <<X:n>> placeholders and leave the result to
// Lingoona. This allows for some substitution inside <<>> rules, and is
// enough for our purposes. <<X:n>> placeholders are substituted
// untransformed, so the behaviour is consistent with what Lingoona 1.7.0 or
// later would do.
return lru_cache_.Get(
name, args,
() => {
string template = Localizer.GetStringByTag(name);
// KSP substitutes arguments that are themselves localization keys,
// e.g., the names of the default vessels.
var resolved_args = new List<string>();
foreach (var arg in args) {
// KSP treats nulls as empty strings here (but not in the overload
// that takes objects).
resolved_args.Add(
arg == null ? "" : (Localizer.Tags.GetValueOrNull(arg) ?? arg));
}
for (int n = 1; n <= resolved_args.Count; ++n) {
template.Replace($"<<X:{n}>>", resolved_args[n - 1]);
}
// These escapes are handled by KSP *after* formatting, contrary to
// the \u ones and the 「」 for {}, which are handled when the Localizer
// loads the tags.
return Lingoona.Grammar.useGrammar(template, resolved_args)
.Replace(@"\n", "\n").Replace(@"\""", "\"").Replace(@"\t", "\t");
});
string template = Localizer.GetStringByTag(name);
for (int n = 1; n <= resolved_args.Count; ++n) {
template.Replace($"<<X:{n}>>", resolved_args[n - 1]);
}

Lingoona.Grammar.setLanguage(UILanguage());
// These escapes are handled by KSP *after* formatting, contrary to
// the \u ones and the 「」 for {}, which are handled when the Localizer
// loads the tags.
var result = Lingoona.Grammar.useGrammar(template, resolved_args)
.Replace(@"\n", "\n").Replace(@"\""", "\"").Replace(@"\t", "\t");
Lingoona.Grammar.setLanguage(Localizer.CurrentLanguage);
return result;
}

public static string CacheFormat(string name, params object[] args) {