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

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

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

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

@ -51,10 +51,10 @@ namespace Fungus
FlowchartMenuItems.SpawnPrefab("StagePosition"); FlowchartMenuItems.SpawnPrefab("StagePosition");
} }
[MenuItem("Tools/Fungus/Create/Language", false, 57)] [MenuItem("Tools/Fungus/Create/Localization", false, 57)]
static void CreateLanguage() 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. * 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) * 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 * Temp storage for a single item of standard text and its localizations
*/ */
protected class LanguageItem protected class TextItem
{ {
public string description; public string description;
public string standardText; 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() public virtual string GetCSVData()
{ {
// Collect all the language items present in the scene // Collect all the text items present in the scene
Dictionary<string, LanguageItem> languageItems = FindLanguageItems(); 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 && if (localizationFile != null &&
localizationFile.text.Length > 0) 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 // Build CSV header row and a list of the language codes currently in use
string csvHeader = "Key,Description,Standard"; string csvHeader = "Key,Description,Standard";
List<string> languageCodes = new List<string>(); 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)) 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; int rowCount = 0;
string csvData = csvHeader + "\n"; 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); string row = CSVSupport.Escape(stringId);
row += "," + CSVSupport.Escape(languageItem.description); row += "," + CSVSupport.Escape(textItem.description);
row += "," + CSVSupport.Escape(languageItem.standardText); row += "," + CSVSupport.Escape(textItem.standardText);
foreach (string languageCode in languageCodes) 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 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 // Export all character names
foreach (Character character in GameObject.FindObjectsOfType<Character>()) foreach (Character character in GameObject.FindObjectsOfType<Character>())
{ {
// String id for character names is CHARACTER.<Character Name> // String id for character names is CHARACTER.<Character Name>
LanguageItem languageItem = new LanguageItem(); TextItem textItem = new TextItem();
languageItem.standardText = character.nameText; textItem.standardText = character.nameText;
languageItem.description = character.description; textItem.description = character.description;
string stringId = "CHARACTER." + character.nameText; string stringId = "CHARACTER." + character.nameText;
languageItems[stringId] = languageItem; textItems[stringId] = textItem;
} }
// Export all Say and Menu commands in the scene // Export all Say and Menu commands in the scene
@ -180,31 +180,31 @@ namespace Fungus
continue; continue;
} }
LanguageItem languageItem = null; TextItem textItem = null;
if (languageItems.ContainsKey(stringId)) if (textItems.ContainsKey(stringId))
{ {
languageItem = languageItems[stringId]; textItem = textItems[stringId];
} }
else else
{ {
languageItem = new LanguageItem(); textItem = new TextItem();
languageItems[stringId] = languageItem; textItems[stringId] = textItem;
} }
// Update basic properties,leaving localised strings intact // Update basic properties,leaving localised strings intact
languageItem.standardText = standardText; textItem.standardText = standardText;
languageItem.description = description; 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(); CsvParser csvParser = new CsvParser();
string[][] csvTable = csvParser.Parse(csvData); string[][] csvTable = csvParser.Parse(csvData);
@ -229,13 +229,13 @@ namespace Fungus
string stringId = fields[0]; string stringId = fields[0];
if (!languageItems.ContainsKey(stringId)) if (!textItems.ContainsKey(stringId))
{ {
continue; continue;
} }
// Store localized strings for this string id // Store localized strings for this string id
LanguageItem languageItem = languageItems[stringId]; TextItem textItem = textItems[stringId];
for (int j = 3; j < fields.Length; ++j) for (int j = 3; j < fields.Length; ++j)
{ {
if (j >= columnNames.Length) if (j >= columnNames.Length)
@ -247,7 +247,7 @@ namespace Fungus
if (languageEntry.Length > 0) if (languageEntry.Length > 0)
{ {
languageItem.localizedStrings[languageCode] = languageEntry; textItem.localizedStrings[languageCode] = languageEntry;
} }
} }
} }
@ -451,19 +451,19 @@ namespace Fungus
*/ */
public virtual string GetStandardText() public virtual string GetStandardText()
{ {
// Collect all the language items present in the scene // Collect all the text items present in the scene
Dictionary<string, LanguageItem> languageItems = FindLanguageItems(); Dictionary<string, TextItem> textItems = FindTextItems();
string textData = ""; string textData = "";
int rowCount = 0; int rowCount = 0;
foreach (string stringId in languageItems.Keys) foreach (string stringId in textItems.Keys)
{ {
if (!stringId.StartsWith("SAY.") && !(stringId.StartsWith("MENU."))) if (!stringId.StartsWith("SAY.") && !(stringId.StartsWith("MENU.")))
{ {
continue; continue;
} }
LanguageItem languageItem = languageItems[stringId]; TextItem languageItem = textItems[stringId];
textData += "#" + stringId + "\n"; textData += "#" + stringId + "\n";
textData += languageItem.standardText.Trim() + "\n\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