Fall back to English for missing strings

A placeholder string is still returned if the English translation is
missing or incomplete
Branch_2.1.x
Nathan Crawford 2013-12-11 19:33:07 -05:00
rodzic 00779d20e5
commit 7b3cc3f7d6
4 zmienionych plików z 15 dodań i 0 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ namespace embroideryReader
{ {
private const string TRANSLATIONS_FOLDER = "translations"; private const string TRANSLATIONS_FOLDER = "translations";
private const string TRANSLATION_FILE_EXT = ".ini"; private const string TRANSLATION_FILE_EXT = ".ini";
private const string DEFAULT_TRANSLATION_NAME = "English (EN-US)";
// String IDs // String IDs
public enum StringID { public enum StringID {
@ -77,12 +78,14 @@ namespace embroideryReader
ENABLE_TRANSPARENCY_GRID, ENABLE_TRANSPARENCY_GRID,
LANGUAGE, LANGUAGE,
GRID_SIZE, GRID_SIZE,
TRANSLATION_INCOMPLETE,
// This must be last. Used for checking completeness of translation files. // This must be last. Used for checking completeness of translation files.
TOTAL_COUNT, TOTAL_COUNT,
}; };
IniFile translationFile; IniFile translationFile;
IniFile defaultFile;
public Translation(String name) public Translation(String name)
{ {
@ -109,6 +112,7 @@ namespace embroideryReader
public void Load(String translationName) public void Load(String translationName)
{ {
translationFile = new IniFile(System.IO.Path.Combine(TRANSLATIONS_FOLDER, translationName + TRANSLATION_FILE_EXT)); translationFile = new IniFile(System.IO.Path.Combine(TRANSLATIONS_FOLDER, translationName + TRANSLATION_FILE_EXT));
defaultFile = new IniFile(System.IO.Path.Combine(TRANSLATIONS_FOLDER, DEFAULT_TRANSLATION_NAME + TRANSLATION_FILE_EXT));
} }
// Returns the translated string, or a string representation of the // Returns the translated string, or a string representation of the
@ -117,10 +121,19 @@ namespace embroideryReader
{ {
string retval; string retval;
retval = translationFile.getValue(sid.ToString()); retval = translationFile.getValue(sid.ToString());
// Check the default translation if string is not found in the loaded translation
if (retval == null)
{
retval = defaultFile.getValue(sid.ToString());
}
// If it's not found in the default, return a placeholder string
if (retval == null) if (retval == null)
{ {
retval = "%" + sid.ToString() + "%"; retval = "%" + sid.ToString() + "%";
} }
return retval; return retval;
} }

Wyświetl plik

@ -161,6 +161,7 @@ namespace embroideryReader
txtGridSize.Left = lblGridSize.Left + lblGridSize.Width + 5; txtGridSize.Left = lblGridSize.Left + lblGridSize.Width + 5;
lblGridSizePixels.Text = translation.GetTranslatedString(Translation.StringID.PIXELS); lblGridSizePixels.Text = translation.GetTranslatedString(Translation.StringID.PIXELS);
lblGridSizePixels.Left = txtGridSize.Left + txtGridSize.Width + 5; lblGridSizePixels.Left = txtGridSize.Left + txtGridSize.Width + 5;
lblIncompleteTranslation.Text = translation.GetTranslatedString(Translation.StringID.TRANSLATION_INCOMPLETE);
} }
private void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e) private void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e)

Wyświetl plik

@ -61,3 +61,4 @@ ENABLE_TRANSPARENCY_GRID=Enable transparency grid
LANGUAGE=Language LANGUAGE=Language
OK=OK OK=OK
GRID_SIZE=Grid size: GRID_SIZE=Grid size:
TRANSLATION_INCOMPLETE=Translation is incomplete

Plik binarny nie jest wyświetlany.