-
-
Save Adirelle/c9186e8f61776c9ea2b45a64811f14fe to your computer and use it in GitHub Desktop.
Rimworld - French Language Worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class LanguageWorker | |
{ | |
public virtual string WithIndefiniteArticle(string str, Gender gender, bool plural = false, bool name = false) | |
{ | |
if( str.NullOrEmpty() ) | |
return ""; | |
//By default names don't get articles | |
if( name ) | |
return str; | |
if( Translator.CanTranslate( "IndefiniteForm" ) ) | |
return "IndefiniteForm".Translate(str); | |
else | |
return "IndefiniteArticle".Translate() + " " + str; | |
} | |
public string WithIndefiniteArticle(string str, bool plural = false, bool name = false) | |
{ | |
return WithIndefiniteArticle(str, LanguageDatabase.activeLanguage.ResolveGender(str), plural, name); | |
} | |
public string WithIndefiniteArticlePostProcessed(string str, Gender gender, bool plural = false, bool name = false) | |
{ | |
return PostProcessed(WithIndefiniteArticle(str, gender, plural, name)); | |
} | |
public string WithIndefiniteArticlePostProcessed(string str, bool plural = false, bool name = false) | |
{ | |
return PostProcessed(WithIndefiniteArticle(str, plural, name)); | |
} | |
public virtual string WithDefiniteArticle(string str, Gender gender, bool plural = false, bool name = false) | |
{ | |
if( str.NullOrEmpty() ) | |
return ""; | |
//By default names don't get articles | |
if( name ) | |
return str; | |
if( Translator.CanTranslate( "DefiniteForm" ) ) | |
return "DefiniteForm".Translate(str); | |
else | |
return "DefiniteArticle".Translate() + " " + str; | |
} | |
public string WithDefiniteArticle(string str, bool plural = false, bool name = false) | |
{ | |
return WithDefiniteArticle(str, LanguageDatabase.activeLanguage.ResolveGender(str), plural, name); | |
} | |
public string WithDefiniteArticlePostProcessed(string str, Gender gender, bool plural = false, bool name = false) | |
{ | |
return PostProcessed(WithDefiniteArticle(str, gender, plural, name)); | |
} | |
public string WithDefiniteArticlePostProcessed(string str, bool plural = false, bool name = false) | |
{ | |
return PostProcessed(WithDefiniteArticle(str, plural, name)); | |
} | |
public virtual string OrdinalNumber(int number, Gender gender = Gender.None) | |
{ | |
return number.ToString(); | |
} | |
public virtual string PostProcessed(string str) | |
{ | |
//Fix double-spaces | |
str = str.MergeMultipleSpaces(); | |
return str; | |
} | |
public virtual string ToTitleCase(string str) | |
{ | |
if( str.NullOrEmpty() ) | |
return str; | |
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str); | |
} | |
public virtual string Pluralize(string str, Gender gender, int count = -1) | |
{ | |
return str; | |
} | |
public string Pluralize(string str, int count = -1) | |
{ | |
return Pluralize(str, LanguageDatabase.activeLanguage.ResolveGender(str), count); | |
} | |
public virtual string PostProcessedKeyedTranslation(string translation) | |
{ | |
return translation; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LanguageWorker_French : LanguageWorker | |
{ | |
public override string WithIndefiniteArticle(string str, Gender gender, bool plural = false, bool name = false) | |
{ | |
//Names don't get articles | |
if( name ) | |
return str; | |
if( plural ) | |
return "des " + str; | |
return (gender == Gender.Female ? "une " : "un ") + str; | |
} | |
public override string WithDefiniteArticle(string str, Gender gender, bool plural = false, bool name = false) | |
{ | |
if( str.NullOrEmpty() ) | |
return str; | |
//Names don't get articles | |
if( name ) | |
return str; | |
if( plural ) | |
return "les " + str; | |
char first = str[0]; | |
if( IsVowel(first) ) | |
return "l'" + str; | |
return (gender == Gender.Female ? "la " : "le ") + str; | |
} | |
public override string OrdinalNumber(int number, Gender gender = Gender.None) | |
{ | |
return number == 1 ? number + "er" : number + "e"; | |
} | |
public override string Pluralize(string str, Gender gender, int count = -1) | |
{ | |
if( str.NullOrEmpty() ) | |
return str; | |
// TODO: should str be lowercased before the tests? | |
// words ending with "s", "x" or "z": do not change anything, | |
char last = str[str.Length - 1]; | |
if( last == 's' || last == 'x' || last == 'z' ) | |
return str; | |
// exceptions to the next rules; only test words that could possibly be found in Rimworld | |
switch( str ) { | |
// "bail", "corail", "émail", "gemmail", "soupirail", "travail", "vantail", "vitrail": replace "ail" by "aux" | |
case "travail": | |
return str.Substring(0, str.Length - 3) + "aux"; | |
// "bleu", "émeu", "landau", "lieu", "pneu", "sarrau", "bal", "banal", "fatal", "final", "festival": append "s" | |
case "bleu": | |
case "émeu": | |
case "lieu": | |
case "banal": | |
case "fatal": | |
case "final": | |
return str + "s"; | |
// "bijou", "caillou", "chou", "genou", "hibou", "joujou", "pou": append "x" | |
case "bijou": | |
case "caillou": | |
case "genou": | |
return str + "x"; | |
} | |
// words ending with "al": replace "al" by "aux" | |
if( str.EndsWith("al") ) | |
return str.Substring(0, str.Length - 2) + "aux"; | |
// words ending with "au" or "eu": append "x" | |
if( str.EndsWith("au") | str.EndsWith("eu") ) | |
return str + "x"; | |
// general case: append s | |
return str + "s"; | |
} | |
public override string PostProcessed(string str) | |
{ | |
return PostProcessedInt(base.PostProcessed(str)); | |
} | |
public override string PostProcessedKeyedTranslation(string translation) | |
{ | |
return PostProcessedInt(base.PostProcessedKeyedTranslation(translation)); | |
} | |
public bool IsVowel(char ch) | |
{ | |
return "aàâäæeéèêëiîïoôöœuùüûhAÀÂÄÆEÉÈÊËIÎÏOÔÖŒUÙÜÛH".IndexOf(ch) >= 0; | |
} | |
private string PostProcessedInt(string str) | |
{ | |
// Note: should spaces be added before and after to simulate "word boundaries" ? | |
return str | |
.Replace(" de le ", " du ") | |
.Replace(" de les ", " des ") | |
.Replace(" de des ", " des ") | |
.Replace(" à le ", " au ") | |
.Replace(" à les ", " aux ") | |
.Replace(" si il ", " s'il ") | |
.Replace(" si ils ", " s'ils ") | |
// the following rules could probably be generalized to "que/lorsque" before all vowels | |
// and should also be applied at the start of the string | |
.Replace(" que il ", " qu'il ") | |
.Replace(" que il ", " qu'ils ") | |
.Replace(" que elle ", " qu'elle ") | |
.Replace(" que elles ", " qu'elles ") | |
.Replace(" lorsque il ", " lorsqu'il ") | |
.Replace(" lorsque il ", " lorsqu'ils ") | |
.Replace(" lorsque elle ", " lorsqu'elle ") | |
.Replace(" lorsque elles ", " lorsqu'elles "); | |
// TODO: other elision rules: "le/la/de []" > "l'/l'/d'[vowel]" | |
} | |
} |
The letters "yY" should be removed from the vowels list since definite article for these is not "l'". Ex : "the yacht" -> "le yacht" not "l'yacht".
There are exceptions too, but most them seems to be proper nouns (l'Yonne, ).
- Most of words starting with "h" (case of so called 'h muet') get " l' " but there are exceptions. Ex: "the man" -> "l'homme", "l'hortensia"
but "la hotte". Unless someone could define the grammatical rule for that, I would treat this as a general case and process the exception differently. The idea is that in RimWorld, the words with that exception are really rare.
The exceptions are words starting with an aspirated h (like "haricot"). In our case we would have to list them (or at least the ones in the files).
References:
Fixed the list of vowels.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 97 : remove "yY" and add "hH"
Exceptions for elisions can be handled one by one by using non-breaking spaces.
I already had to deal with that somewhere in the translation files. For example in sentences such as "Le but est de le capturer" instead of "Le but est
ducapturer", elision has been deactivated by hand since "le" here is a pronoun not an article.