Example #1
0
    public void LoadLocalisedText(string fileName)
    {
        localisedText = new Dictionary <string, string>();
        string filePath = Path.Combine(Application.streamingAssetsPath, fileName);

        if (File.Exists(filePath))
        {
            string           dataAsJson = File.ReadAllText(filePath);
            LocalisationData loadedData = JsonUtility.FromJson <LocalisationData>(dataAsJson);

            for (int i = 0; i < loadedData.items.Length; i++)
            {
                localisedText.Add(loadedData.items[i].key, loadedData.items[i].value);
                keys.Add(loadedData.items[i].key);
            }


            Debug.Log("Data loaded, dictionary contains: " + localisedText.Count + " entries");
        }
        else
        {
            Debug.LogError("Cannot find file!");
        }

        isReady = true;
    }
Example #2
0
    public void LoadLocalisedText(string fileName)
    {
        LocalisationData loadedData = null;

        localisedText = new Dictionary <string, string>();
        string filePath = Path.Combine("jar:file://" + Application.dataPath + "!/assets/", fileName);

        if (Application.platform == RuntimePlatform.Android)
        {
            // Android
            filePath = System.IO.Path.Combine(Application.streamingAssetsPath, fileName);

            WWW reader = new WWW(filePath);
            while (!reader.isDone)
            {
            }
            loadedData = JsonUtility.FromJson <LocalisationData>(reader.text);
        }
        else
        {
            filePath = Path.Combine(Application.streamingAssetsPath, fileName); // PC
            string dataAsJSON = File.ReadAllText(filePath);
            loadedData = JsonUtility.FromJson <LocalisationData>(dataAsJSON);
        }

        for (int i = 0; i < loadedData.items.Length; i++)
        {
            localisedText.Add(loadedData.items[i].key, loadedData.items[i].value);
            keys.Add(loadedData.items[i].key);
        }
    }
Example #3
0
        public void LoadCsv(string csvData, string[] languages, string[] keys, string[,] values)
        {
            // Arrange
            using (var rdr = new System.IO.StringReader(csvData))
            {
                //// Act
                var localisationData = LocalisationData.LoadCsv(rdr);

                //// Assert
                Assert.AreEqual(languages.Length, localisationData.Languages.Count, "Languages not setup as expected");
                Assert.AreEqual(keys.Length, localisationData.Entries.Count, "Entries not setup as expected");
                foreach (var language in languages)
                {
                    Assert.IsTrue(localisationData.GetLanguage(language) != null, "Missing language " + language);
                }
                for (var i = 0; i < keys.Length; i++)
                {
                    var key = keys[i];
                    Assert.IsTrue(localisationData.GetEntry(key) != null, "Missing entry " + key);
                    for (var l = 0; l < languages.Length; l++)
                    {
                        var language = languages[l];
                        Assert.AreEqual(values[i, l], localisationData.GetText(key, language), "Values are not the same.");
                    }
                }
            }
        }
Example #4
0
    /*
     *  void OnEnable() {
     *          SceneManager.sceneLoaded += OnSceneLoaded;
     *  }
     *
     *  void OnDisable() {
     *          SceneManager.sceneLoaded -= OnSceneLoaded;
     *  }
     *
     *
     *  void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
     *          languages_Dropdown = FindObjectOfType<Dropdown>();
     *          if (languages_Dropdown == null)
     *          {
     *                  Debug.Log("No Dropdown");
     *          }
     *          else
     *          {
     *                  Debug.Log("Dropdown: " + languages_Dropdown.name);
     *          }
     *
     *          if (PlayerPrefs.HasKey("activeLanguage"))
     *          {
     *                  activeLanguage = PlayerPrefs.GetInt("activeLanguage");
     *                  if (languages_Dropdown != null)
     *                  {
     *                          languages_Dropdown.value = activeLanguage;
     *                  }
     *          }
     *
     *          Set_Language();
     *  }*/

    public void LoadLocalisedText(string fileName)
    {
        localisedText = new Dictionary <string, string>();
        string filePath = Path.Combine(Application.streamingAssetsPath, fileName);

        if (File.Exists(filePath))
        {
            string           dataAsJson = File.ReadAllText(filePath);
            LocalisationData loadedData = JsonUtility.FromJson <LocalisationData>(dataAsJson);

            for (int i = 0; i < loadedData.items.Length; i++)
            {
                localisedText.Add(loadedData.items[i].key, loadedData.items[i].value);
            }
        }
        else
        {
            Debug.LogError("Cannot find file!");
        }

        isReady = true;

        GameObject[] textGOs = GameObject.FindGameObjectsWithTag("Localised_Text");
        for (int i = 0; i < textGOs.Length; i++)
        {
            textGOs[i].GetComponent <LocalisedText>().UpdateText();
            //			Text text = textGOs[i].GetComponent<Text>();
            //			text.text = GetLocalisedValue(textGOs[i].GetComponent<LocalisedText>().key);
        }
    }
Example #5
0
    public void LoadLocalisedText(string fileName)
    {
        //TODO: Create new dictionary if language has changed... (Separate method to handle language change?)
        if (localisedText == null)
        {
            localisedText = new Dictionary <string, string>();
        }

        string filePath = Path.Combine(Application.streamingAssetsPath, fileName);

        if (File.Exists(filePath))
        {
            string           dataAsJson = File.ReadAllText(filePath);
            LocalisationData loadedData = JsonUtility.FromJson <LocalisationData> (dataAsJson);

            for (int i = 0; i < loadedData.items.Length; i++)
            {
                localisedText.Add(loadedData.items[i].key, loadedData.items[i].value);
            }
        }
        else
        {
            Debug.LogError("Cannot find localisation files for language!");
        }
        Debug.Log("Loaded localisation. Database contains: " + localisedText.Count + " entries.");
    }
Example #6
0
 internal TextHolder(LocalisationData localisationData)
 {
     if (_dataDictionary == null)
     {
         _dataDictionary = new Dictionary <string, Dictionary <PGLanguages, Translation> >();
     }
     Import(localisationData);
 }
Example #7
0
    private void LoadGameData()
    {
        string filePath = EditorUtility.OpenFilePanel("Select localisation data file", Application.streamingAssetsPath, "json");

        if (!string.IsNullOrEmpty(filePath))
        {
            string dataAsJson = File.ReadAllText(filePath);

            localisationData = JsonUtility.FromJson <LocalisationData> (dataAsJson);
        }
    }
        private async Task <Tuple <DistanceData, LocalisationData> > GetCurrentPosition()
        {
            if (this.ProviderState < ProviderState.StartedRecord)
            {
                return(Tuple.Create((DistanceData)null, (LocalisationData)null));
            }
            else
            {
                DistanceData distance = await AgentBroker.Instance.TryExecuteOnFirst <IDistanceAgent, DistanceData>(a => a.CurrentData).GetValueOrDefault().ConfigureAwait(false);

                LocalisationData localisation = await AgentBroker.Instance.TryExecuteOnFirst <ILocalisationAgent, LocalisationData>(a => a.CurrentData).GetValueOrDefault().ConfigureAwait(false);

                return(Tuple.Create(distance, localisation));
            }
        }
Example #9
0
        /// <summary>
        /// Fills a LocalisationData with the specified languages and keys and values in the format key-language
        /// </summary>
        /// <param name="localisationData"></param>
        /// <param name="languages"></param>
        /// <param name="keys"></param>
        internal static void FillLocalisationData(LocalisationData localisationData, string[] languages, string[] keys)
        {
            foreach (var language in languages)
            {
                localisationData.AddLanguage(language);
            }

            foreach (var key in keys)
            {
                var entry = localisationData.AddEntry(key);
                for (var i = 0; i < languages.Length; i++)
                {
                    entry.Languages[i] = key + "-" + languages[i];
                }
            }
        }
Example #10
0
        /// <summary>
        /// Localise the specified value based on the currently set language.
        /// </summary>
        /// If language is specific then this method will try and get the key for that particular value, returning null if not found unless
        /// missingReturnsKey is set in which case the key will be returned.
        public static string GetText(string key, string language = null, bool missingReturnsKey = false)
        {
            string text;

            Load();
            if (language == null)
            {
                text = LocalisationData.GetText(key, _languageIndex);
            }
            else
            {
                text = LocalisationData.GetText(key, language);
            }

            return((text != null || !missingReturnsKey) ? text : key);
        }
        private void UpdateData(LocalisationData data)
        {
            try
            {
                txtLatitude.Text  = data.CorrectedData.PositionData.Latitude.ToString("F7");
                txtLongitude.Text = data.CorrectedData.PositionData.Longitude.ToString("F7");
                txtAltitude.Text  = data.CorrectedData.PositionData.Altitude.ToString("F2");

                txtSpeedKmh.Text = data.CorrectedData.VelocityData.SpeedKmh.ToString("F2");
                txtSpeedMs.Text  = data.CorrectedData.VelocityData.SpeedMs.ToString("F2");
                txtTime.Text     = data.CorrectedData.PositionData.Utc.ToString("yyyy-MM-dd HH:mm:ss.fff");

                switch (data.GpsStatus)
                {
                case GpsStatus.Initializing:
                    txtStatut.Text = "Initializing...";
                    break;

                case GpsStatus.Reliable:
                    txtStatut.Text = "Reliable signal";
                    break;

                case GpsStatus.SignalLost:
                    txtStatut.Text = "Lost signal";
                    break;

                case GpsStatus.MultiPathDetected:
                    txtStatut.Text = "Multiple paths detected";
                    break;

                default:
                    txtStatut.Text = "Unknown";
                    break;
                }

                txtNbSatellite.Text = data.CorrectedData.PositionData.NbSatellites.ToString();
                txtPdop.Text        = data.CorrectedData.PrecisionData.Pdop.ToString();
            }
            catch (Exception ex)
            {
                Log.Error().Message(string.Format("Error while showing GPS data: '{0}'", ex.Message)).Exception(ex).WithAgent(this.ParentAgent.Id).Write();
            }
        }
Example #12
0
 protected void DrawTools()
 {
     EditorGUILayout.BeginVertical("Box");
     EditorGUILayout.LabelField(new GUIContent("Import / Export", ""), EditorStyles.boldLabel);
     _importExportHelpRect = EditorHelper.ShowHideableHelpBox("GameFramework.LocalisationEditorWindow.ImportExport", "If you would like to edit the data outside Unity then you can import from and export to .csv (text) files. Entries from any imported file will be merged with existing entries, replacing any keys that already exist with a similar name.\n\nIf you have previously used .csv files for localisation then you should use the import button to import old files into the new localisation system", _importExportHelpRect);
     if (GUILayout.Button("Import csv", EditorStyles.miniButton))
     {
         var newFileName = EditorUtility.OpenFilePanel("Select a .csv localisation file", _importExportFilename, "csv");
         if (!string.IsNullOrEmpty(newFileName))
         {
             _importExportFilename = newFileName;
             var importedLocalisationData = LocalisationData.LoadCsv(_importExportFilename);
             if (importedLocalisationData != null)
             {
                 Undo.RecordObject(_targetLocalisationData, "Import Localisation Csv");
                 _targetLocalisationData.Merge(importedLocalisationData);
                 _targetChanged = true;
                 EditorUtility.DisplayDialog("Localisation Import", string.Format("Import Complete!\n\nImported {0} languages and {1} entries.", importedLocalisationData.Languages.Count, importedLocalisationData.Entries.Count), "Ok");
             }
             else
             {
                 EditorUtility.DisplayDialog("Localisation Import", "Import failed!\n\nSee the console window for further details.", "Ok");
             }
         }
     }
     if (GUILayout.Button("Export csv", EditorStyles.miniButton))
     {
         var newFileName = EditorUtility.SaveFilePanel("Select a .csv localisation file", _importExportFilename, "localisation", "csv");
         if (!string.IsNullOrEmpty(newFileName))
         {
             _importExportFilename = newFileName;
             if (_targetLocalisationData.WriteCsv(_importExportFilename))
             {
                 EditorUtility.DisplayDialog("Localisation Export", "Export complete!", "Ok");
             }
             else
             {
                 EditorUtility.DisplayDialog("Localisation Export", "Export failed!\n\nSee the console window for further details.", "Ok");
             }
         }
     }
     EditorGUILayout.EndVertical();
 }
Example #13
0
        protected virtual void OnEnable()
        {
            _targetLocalisationData = target as LocalisationData;

            // setup for entries tab
            // set scroll height to initial value (full screen height) - we can later set to the correct size in Repaint event.
            _entryReferenceList = new List <EntryReference>();
            if (_entriesScrollHeight <= 0)
            {
                _entriesScrollHeight = Screen.height;
            }

            // setup for languages tab
            _languagesProperty = serializedObject.FindProperty("_languages");
            _languagesCount    = -1;

            // setup for tools tab
            _importExportFilename = Application.dataPath;
        }
Example #14
0
        internal void Import(LocalisationData localisationData)
        {
            foreach (Localisation localisation in localisationData.LocalisationHolder)
            {
                if (_dataDictionary.ContainsKey(localisation.Key))
                {
                    if (_dataDictionary[localisation.Key] != null)
                    {
                        foreach (Translation translation in localisation.TranslationData.TranslationHolder)
                        {
                            if (!_dataDictionary[localisation.Key].ContainsKey(PGLanguageUtility.ToPGLanguage(translation.Language)))
                            {
                                _dataDictionary[localisation.Key].Add(PGLanguageUtility.ToPGLanguage(translation.Language), translation);
                            }
                            else
                            {
                                _dataDictionary[localisation.Key][PGLanguageUtility.ToPGLanguage(translation.Language)] = translation;
                            }
                        }
                    }
                    else
                    {
                        Dictionary <PGLanguages, Translation> dic = new Dictionary <PGLanguages, Translation>();
                        foreach (Translation translation in localisation.TranslationData.TranslationHolder)
                        {
                            dic.Add(PGLanguageUtility.ToPGLanguage(translation.Language), translation);
                        }

                        _dataDictionary[localisation.Key] = dic;
                    }
                }
                else
                {
                    Dictionary <PGLanguages, Translation> dic = new Dictionary <PGLanguages, Translation>();
                    foreach (Translation translation in localisation.TranslationData.TranslationHolder)
                    {
                        dic.Add(PGLanguageUtility.ToPGLanguage(translation.Language), translation);
                    }
                    _dataDictionary.Add(localisation.Key, dic);
                }
            }
        }
Example #15
0
        /// <summary>
        /// Returns whether the passed language can be used (is in the loaded definition and in supported languages).
        /// </summary>
        /// <param name="language"></param>
        /// <returns></returns>
        public static bool CanUseLanguage(string language)
        {
            if (LocalisationData == null)
            {
                return(false);
            }

            // make sure it is loaded
            if (!LocalisationData.ContainsLanguage(language))
            {
                return(false);
            }

            // make sure it is supported
            if (!SupportedLanguages.Contains(language))
            {
                return(false);
            }
            return(true);
        }
Example #16
0
    public void LoadlocalisedText()
    {
        LanguageOption currentLang = DataManager.instance.LanguageOption;
        string         fileName;

        if (currentLang == LanguageOption.EnglishUk)
        {
            fileName = _entextFile;
        }
        else if (currentLang == LanguageOption.Japanese)
        {
            fileName = _jptextFile;
        }
        else
        {
            Debug.Log("Unrecognised language; defaulting to English text file");
            fileName = _entextFile;
        }

        localisedText = new Dictionary <string, string>();
        string filePath = Path.Combine(Application.streamingAssetsPath, fileName);

        if (File.Exists(filePath))
        {
            string           dataAsJson = File.ReadAllText(filePath);
            LocalisationData loadedData = JsonUtility.FromJson <LocalisationData>(dataAsJson);

            for (int i = 0; i < loadedData.items.Length; i++)
            {
                localisedText.Add(loadedData.items[i].key, loadedData.items[i].value);
            }

            Debug.Log("Data loaded, dictionary contains: " + localisedText.Count + " entries");
        }
        else
        {
            Debug.LogError("Cannot find file!");
        }

        isReady = true;
    }
    public void LoadLocalisedText(string filename)
    {
        localisedText = new Dictionary <string, string>();
        string filePath = Path.Combine(Application.streamingAssetsPath, filename);

        if (File.Exists(filePath))
        {
            string           dataAsJson = File.ReadAllText(filePath);
            LocalisationData loadedData = JsonUtility.FromJson <LocalisationData>(dataAsJson);

            for (int i = 0; i < loadedData.items.Length; i++)
            {
                localisedText.Add(loadedData.items[i].keys.ToString(), loadedData.items[i].value);
            }

            Debug.Log(filename + " Data Loaded");
        }
        else
        {
            Debug.LogError("Cannot Find File");
        }
    }
Example #18
0
 internal static void Merge(TextHolder mergeTarget, LocalisationData dataToMerge)
 {
 }
Example #19
0
 /// <summary>
 /// Returns whether the specified key is present.
 /// </summary>
 public static bool Exists(string key)
 {
     Load();
     return(LocalisationData.ContainsEntry(key));
 }
Example #20
0
        /// <summary>
        /// Load LocalisationData files
        /// </summary>
        public static void Reload(LocalisationConfiguration localisationConfiguration = null)
        {
            Clear();

            if (localisationConfiguration == null)
            {
                localisationConfiguration = GameManager.LoadResource <LocalisationConfiguration>("LocalisationConfiguration");
            }
            //localisationConfiguration = GameObject.FindObjectOfType<LocalisationConfiguration>();
            var setupMode = localisationConfiguration == null ? LocalisationConfiguration.SetupModeType.Auto : localisationConfiguration.SetupMode;

            string[] loadedSupportedLanguages = new string[0];

            // set localisation data
            if (setupMode == LocalisationConfiguration.SetupModeType.Auto)
            {
                // Try to load the default Localisation file directly - don't use GameMangager method as we load in 'reverse' as user items
                // should overwrite system ones.
                var asset = Resources.Load <LocalisationData>("Default/Localisation");
                if (asset != null)
                {
                    LocalisationData         = ScriptableObject.Instantiate(asset); // create a copy so we don't overwrite values.
                    loadedSupportedLanguages = asset.GetLanguageNames();
                }

                // try and load identifier localisation if specified and present, or if not user localisation
                var identifierLocalisationLoaded = false;
                if (GameManager.IsActive && GameManager.GetIdentifierBase() != null)
                {
                    asset = Resources.Load <LocalisationData>(GameManager.GetIdentifierBase() + "/Localisation");
                    if (asset != null)
                    {
                        identifierLocalisationLoaded = true;
                        if (LocalisationData == null)
                        {
                            LocalisationData = asset;
                        }
                        else
                        {
                            LocalisationData.Merge(asset);
                        }
                        loadedSupportedLanguages = asset.GetLanguageNames(); // override any previous
                    }
                }
                if (!identifierLocalisationLoaded)
                {
                    asset = Resources.Load <LocalisationData>("Localisation");
                    if (asset != null)
                    {
                        if (LocalisationData == null)
                        {
                            LocalisationData = asset;
                        }
                        else
                        {
                            LocalisationData.Merge(asset);
                        }
                        loadedSupportedLanguages = asset.GetLanguageNames(); // override any previous
                    }
                }
                if (LocalisationData == null)
                {
                    MyDebug.LogWarning("GlobalLocalisation: No localisation data was found so creating an empty one. Please check that a localisation files exist at /Resources/Localisation or /Resources/Default/Localisation!");
                }
            }
            else if (setupMode == LocalisationConfiguration.SetupModeType.Specified)
            {
                foreach (var localisationData in localisationConfiguration.SpecifiedLocalisationData)
                {
                    // first item gets loaded / copied, subsequent get merged into this.
                    if (LocalisationData == null)
                    {
                        LocalisationData = ScriptableObject.Instantiate(localisationData);  // create a copy so we don't overwrite values.
                    }
                    else
                    {
                        LocalisationData.Merge(localisationData);
                    }
                    loadedSupportedLanguages = localisationData.GetLanguageNames(); // if exists override
                }
                if (LocalisationData == null)
                {
                    MyDebug.LogWarning("GlobalLocalisation: No localisation data was found so creating an empty one. Please check that localisation files exist and are in the correct location!");
                }
            }

            // if nothing loaded then create an empty localisation to avoid errors.
            if (LocalisationData == null)
            {
                LocalisationData = ScriptableObject.CreateInstance <LocalisationData>();
                LocalisationData.AddLanguage("English", "en");
                loadedSupportedLanguages = LocalisationData.GetLanguageNames();
            }

            // set Supported Languages - either from config if present or based upon loaded files.
            if (localisationConfiguration != null && localisationConfiguration.SupportedLanguages.Length > 0)
            {
                List <string> validSupportedLanguages = new List <string>();
                foreach (var language in localisationConfiguration.SupportedLanguages)
                {
                    if (LocalisationData.ContainsLanguage(language))
                    {
                        validSupportedLanguages.Add(language);
                    }
                    else
                    {
                        Debug.Log("GlobalLocalisation: Localisation files do not contain definitions for the specified supported language '" + language + "'");
                    }
                }
                SupportedLanguages = validSupportedLanguages.ToArray();
            }
            else
            {
                SupportedLanguages = loadedSupportedLanguages;
            }


            // if no usable language is already set then set to the default language.
            if (!CanUseLanguage(Language))
            {
                SetLanguageToDefault();
            }
        }
Example #21
0
 private void CreateNewData()
 {
     localisationData = new LocalisationData();
 }
Example #22
0
        private void ProcessCSVData(string data)
        {
            using (CSVParser parser = new CSVParser(data))
            {
                PrepareCharacterMaps();

                if (_properyOutputCharacters.boolValue)
                {
                    BuildCharacterMap(_properyOutputCharactersInclude.stringValue, FindCharacterMap(null));
                }

                string[]           lineCache     = new string[100];
                string[]           languageCodes = null;
                LocalisationKeys   keys          = new LocalisationKeys();
                LocalisationData[] dataArr       = null;

                // parse CSV contents
                int i = 0, headers = 0;
                while (parser.Peek() != -1)
                {
                    int j = 0, k = parser.ParseCSVLineNonAlloc(lineCache, i > 0 ? headers : lineCache.Length, i > 0);
                    if (i == 0)
                    {
                        // parse header
                        headers       = k;
                        dataArr       = new LocalisationData[k - 1];
                        languageCodes = new string[k - 1];

                        for (j = 1; j < k; ++j)
                        {
                            dataArr[j - 1]       = new LocalisationData(lineCache[j]);
                            languageCodes[j - 1] = lineCache[j];
                        }
                    }
                    else
                    {
                        for (j = 0; j < k; ++j)
                        {
                            if (j == 0)
                            {
                                keys.keys.Add(lineCache[j]);
                            }
                            else
                            {
                                LocalisationData d = dataArr[j - 1];
                                d.strings.Add(lineCache[j]);
                                if (_properyOutputCharacters.boolValue)
                                {
                                    string language = languageCodes[j - 1];
                                    BuildCharacterMap(lineCache[j], FindCharacterMap(language), _properyOutputCharactersInclude.stringValue);
                                }
                            }
                        }
                    }

                    ++i;
                }

                // save assets as .json
                string outputDir = string.Format("Assets{0}StreamingAssets{0}Localisation", Path.DirectorySeparatorChar);
                if (!Directory.Exists(outputDir))
                {
                    Directory.CreateDirectory(outputDir);
                }

                int l = dataArr.Length;
                for (i = 0; i < l; ++i)
                {
                    LocalisationData d = dataArr[i];

                    string fileName = string.Format("strings_{0}.json", d.code);
                    SaveJSONToFile(fileName, JsonUtility.ToJson(d), outputDir);

                    keys.languageFiles.Add(fileName);
                }

                // save keys
                SaveJSONToFile("keys.json", JsonUtility.ToJson(keys), outputDir);
                SaveJSONToFile("languages.json", JsonUtility.ToJson(new LocalisationLanguages(languageCodes)), outputDir);

                if (_properyOutputCharacters.boolValue)
                {
                    serializedObject.Update();
                    OutputCharacterMaps();
                }
            }

            AssetDatabase.Refresh();
        }
Example #23
0
 internal static void SetLocalisationData(LocalisationData data)
 {
     _localisationDataHolder = data;
 }
Example #24
0
 internal static void Merge(LocalisationData mergeTarget, LocalisationData dataToMerge)
 {
 }