Browse Source

Renamed Language to Localisation for clarity #8

master
chrisgregan 10 years ago
parent
commit
4c41ada4a8
  1. 2
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  2. 36
      Assets/Fungus/Narrative/Editor/LocalizationEditor.cs
  3. 4
      Assets/Fungus/Narrative/Editor/LocalizationEditor.cs.meta
  4. 6
      Assets/Fungus/Narrative/Editor/NarrativeMenuItems.cs
  5. 0
      Assets/Fungus/Narrative/Resources/Localization.prefab
  6. 0
      Assets/Fungus/Narrative/Resources/Localization.prefab.meta
  7. 80
      Assets/Fungus/Narrative/Scripts/Localization.cs
  8. 0
      Assets/Fungus/Narrative/Scripts/Localization.cs.meta

2
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -112,7 +112,7 @@ namespace Fungus
/**
* Unique identifier for identifying this flowchart in localized string keys.
*/
[Tooltip("Unique identifier for this flowchart in localized string keys. An id must be provided for Language string export to work.")]
[Tooltip("Unique identifier for this flowchart in localized string keys. This id must be provided for localization string export to work.")]
public string localizationId = "";
/**

36
Assets/Fungus/Narrative/Editor/LanguageEditor.cs → Assets/Fungus/Narrative/Editor/LocalizationEditor.cs

@ -8,8 +8,8 @@ using Rotorz.ReorderableList;
namespace Fungus
{
[CustomEditor(typeof(Language))]
public class LanguageEditor : Editor
[CustomEditor(typeof(Localization))]
public class LocalizationEditor : Editor
{
protected SerializedProperty activeLanguageProp;
protected SerializedProperty localizationFileProp;
@ -24,30 +24,30 @@ namespace Fungus
{
serializedObject.Update();
Language language = target as Language;
Localization localization = target as Localization;
EditorGUILayout.PropertyField(activeLanguageProp);
EditorGUILayout.PropertyField(localizationFileProp);
if (GUILayout.Button(new GUIContent("Export Localization File")))
{
ExportLocalizationFile(language);
ExportLocalizationFile(localization);
}
if (GUILayout.Button(new GUIContent("Export Standard Text")))
{
ExportStandardText(language);
ExportStandardText(localization);
}
if (GUILayout.Button(new GUIContent("Import Standard Text")))
{
ImportStandardText(language);
ImportStandardText(localization);
}
serializedObject.ApplyModifiedProperties();
}
public virtual void ExportLocalizationFile(Language language)
public virtual void ExportLocalizationFile(Localization localization)
{
string path = EditorUtility.SaveFilePanel("Export Localization File", "Assets/",
"localization.csv", "");
@ -56,14 +56,14 @@ namespace Fungus
return;
}
string csvData = language.GetCSVData();
string csvData = localization.GetCSVData();
File.WriteAllText(path, csvData);
AssetDatabase.Refresh();
ShowNotification(language);
ShowNotification(localization);
}
public virtual void ExportStandardText(Language language)
public virtual void ExportStandardText(Localization localization)
{
string path = EditorUtility.SaveFilePanel("Export Standard Text", "Assets/", "standard.txt", "");
if (path.Length == 0)
@ -71,14 +71,14 @@ namespace Fungus
return;
}
string textData = language.GetStandardText();
string textData = localization.GetStandardText();
File.WriteAllText(path, textData);
AssetDatabase.Refresh();
ShowNotification(language);
ShowNotification(localization);
}
public virtual void ImportStandardText(Language language)
public virtual void ImportStandardText(Localization localization)
{
string path = EditorUtility.OpenFilePanel("Import Standard Text", "Assets/", "txt");
if (path.Length == 0)
@ -87,18 +87,18 @@ namespace Fungus
}
string textData = File.ReadAllText(path);
language.SetStandardText(textData);
localization.SetStandardText(textData);
ShowNotification(language);
ShowNotification(localization);
}
protected virtual void ShowNotification(Language language)
protected virtual void ShowNotification(Localization localization)
{
EditorWindow window = EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart");
if (window != null)
{
window.ShowNotification(new GUIContent(language.notificationText));
language.notificationText = "";
window.ShowNotification(new GUIContent(localization.notificationText));
localization.notificationText = "";
}
}
}

4
Assets/Fungus/Narrative/Editor/LanguageEditor.cs.meta → Assets/Fungus/Narrative/Editor/LocalizationEditor.cs.meta

@ -1,6 +1,6 @@
fileFormatVersion: 2
guid: 73e0ffd2fe9ba4afb995e1587c027556
timeCreated: 1427887512
guid: ab0caac085485491fb32dbf86efefef1
timeCreated: 1428581512
licenseType: Free
MonoImporter:
serializedVersion: 2

6
Assets/Fungus/Narrative/Editor/NarrativeMenuItems.cs

@ -51,10 +51,10 @@ namespace Fungus
FlowchartMenuItems.SpawnPrefab("StagePosition");
}
[MenuItem("Tools/Fungus/Create/Language", false, 57)]
static void CreateLanguage()
[MenuItem("Tools/Fungus/Create/Localization", false, 57)]
static void CreateLocalization()
{
FlowchartMenuItems.SpawnPrefab("Language");
FlowchartMenuItems.SpawnPrefab("Localization");
}
}

0
Assets/Fungus/Narrative/Resources/Language.prefab → Assets/Fungus/Narrative/Resources/Localization.prefab

0
Assets/Fungus/Narrative/Resources/Language.prefab.meta → Assets/Fungus/Narrative/Resources/Localization.prefab.meta

80
Assets/Fungus/Narrative/Scripts/Language.cs → Assets/Fungus/Narrative/Scripts/Localization.cs

@ -14,7 +14,7 @@ namespace Fungus
/**
* Multi-language localization support.
*/
public class Language : MonoBehaviour
public class Localization : MonoBehaviour
{
/**
* Currently active language, usually defined by a two letter language code (e.g DE = German)
@ -26,7 +26,7 @@ namespace Fungus
/**
* Temp storage for a single item of standard text and its localizations
*/
protected class LanguageItem
protected class TextItem
{
public string description;
public string standardText;
@ -55,26 +55,26 @@ namespace Fungus
}
/**
* Convert all language items and localized strings to an easy to edit CSV format.
* Convert all text items and localized strings to an easy to edit CSV format.
*/
public virtual string GetCSVData()
{
// Collect all the language items present in the scene
Dictionary<string, LanguageItem> languageItems = FindLanguageItems();
// Collect all the text items present in the scene
Dictionary<string, TextItem> textItems = FindTextItems();
// Update language items with localization data from CSV file
// Update text items with localization data from CSV file
if (localizationFile != null &&
localizationFile.text.Length > 0)
{
AddLocalizedStrings(languageItems, localizationFile.text);
AddLocalizedStrings(textItems, localizationFile.text);
}
// Build CSV header row and a list of the language codes currently in use
string csvHeader = "Key,Description,Standard";
List<string> languageCodes = new List<string>();
foreach (LanguageItem languageItem in languageItems.Values)
foreach (TextItem textItem in textItems.Values)
{
foreach (string languageCode in languageItem.localizedStrings.Keys)
foreach (string languageCode in textItem.localizedStrings.Keys)
{
if (!languageCodes.Contains(languageCode))
{
@ -84,22 +84,22 @@ namespace Fungus
}
}
// Build the CSV file using collected language items
// Build the CSV file using collected text items
int rowCount = 0;
string csvData = csvHeader + "\n";
foreach (string stringId in languageItems.Keys)
foreach (string stringId in textItems.Keys)
{
LanguageItem languageItem = languageItems[stringId];
TextItem textItem = textItems[stringId];
string row = CSVSupport.Escape(stringId);
row += "," + CSVSupport.Escape(languageItem.description);
row += "," + CSVSupport.Escape(languageItem.standardText);
row += "," + CSVSupport.Escape(textItem.description);
row += "," + CSVSupport.Escape(textItem.standardText);
foreach (string languageCode in languageCodes)
{
if (languageItem.localizedStrings.ContainsKey(languageCode))
if (textItem.localizedStrings.ContainsKey(languageCode))
{
row += "," + CSVSupport.Escape(languageItem.localizedStrings[languageCode]);
row += "," + CSVSupport.Escape(textItem.localizedStrings[languageCode]);
}
else
{
@ -117,21 +117,21 @@ namespace Fungus
}
/**
* Buidls a dictionary of localizable objects in the scene.
* Buidls a dictionary of localizable text items in the scene.
*/
protected Dictionary<string, LanguageItem> FindLanguageItems()
protected Dictionary<string, TextItem> FindTextItems()
{
Dictionary<string, LanguageItem> languageItems = new Dictionary<string, LanguageItem>();
Dictionary<string, TextItem> textItems = new Dictionary<string, TextItem>();
// Export all character names
foreach (Character character in GameObject.FindObjectsOfType<Character>())
{
// String id for character names is CHARACTER.<Character Name>
LanguageItem languageItem = new LanguageItem();
languageItem.standardText = character.nameText;
languageItem.description = character.description;
TextItem textItem = new TextItem();
textItem.standardText = character.nameText;
textItem.description = character.description;
string stringId = "CHARACTER." + character.nameText;
languageItems[stringId] = languageItem;
textItems[stringId] = textItem;
}
// Export all Say and Menu commands in the scene
@ -180,31 +180,31 @@ namespace Fungus
continue;
}
LanguageItem languageItem = null;
if (languageItems.ContainsKey(stringId))
TextItem textItem = null;
if (textItems.ContainsKey(stringId))
{
languageItem = languageItems[stringId];
textItem = textItems[stringId];
}
else
{
languageItem = new LanguageItem();
languageItems[stringId] = languageItem;
textItem = new TextItem();
textItems[stringId] = textItem;
}
// Update basic properties,leaving localised strings intact
languageItem.standardText = standardText;
languageItem.description = description;
textItem.standardText = standardText;
textItem.description = description;
}
}
}
return languageItems;
return textItems;
}
/**
* Adds localized strings from CSV file data to a dictionary of language items in the scene.
* Adds localized strings from CSV file data to a dictionary of text items in the scene.
*/
protected virtual void AddLocalizedStrings(Dictionary<string, LanguageItem> languageItems, string csvData)
protected virtual void AddLocalizedStrings(Dictionary<string, TextItem> textItems, string csvData)
{
CsvParser csvParser = new CsvParser();
string[][] csvTable = csvParser.Parse(csvData);
@ -229,13 +229,13 @@ namespace Fungus
string stringId = fields[0];
if (!languageItems.ContainsKey(stringId))
if (!textItems.ContainsKey(stringId))
{
continue;
}
// Store localized strings for this string id
LanguageItem languageItem = languageItems[stringId];
TextItem textItem = textItems[stringId];
for (int j = 3; j < fields.Length; ++j)
{
if (j >= columnNames.Length)
@ -247,7 +247,7 @@ namespace Fungus
if (languageEntry.Length > 0)
{
languageItem.localizedStrings[languageCode] = languageEntry;
textItem.localizedStrings[languageCode] = languageEntry;
}
}
}
@ -451,19 +451,19 @@ namespace Fungus
*/
public virtual string GetStandardText()
{
// Collect all the language items present in the scene
Dictionary<string, LanguageItem> languageItems = FindLanguageItems();
// Collect all the text items present in the scene
Dictionary<string, TextItem> textItems = FindTextItems();
string textData = "";
int rowCount = 0;
foreach (string stringId in languageItems.Keys)
foreach (string stringId in textItems.Keys)
{
if (!stringId.StartsWith("SAY.") && !(stringId.StartsWith("MENU.")))
{
continue;
}
LanguageItem languageItem = languageItems[stringId];
TextItem languageItem = textItems[stringId];
textData += "#" + stringId + "\n";
textData += languageItem.standardText.Trim() + "\n\n";

0
Assets/Fungus/Narrative/Scripts/Language.cs.meta → Assets/Fungus/Narrative/Scripts/Localization.cs.meta

Loading…
Cancel
Save