Beispiel #1
0
    public static void LoadFile(string fileName, bool giveWarning = true)
    {
        if (!Initialized)
        {
            Logger.Severe("Can't load localization file:\"" + fileName + "\" as Localizer not initialized.", LocalizerID.SEVERE_CANT_LOAD_FILE);
            return;
        }

        string        fullFileName     = FullFileName(fileName);
        LocalizerKeys localizationKeys = JsonReader.ReadJson <LocalizerKeys>(fullFileName);

        if (localizationKeys == default)
        {
            return;     // file failed to load
        }

        // add keys to dictionary
        foreach (LocalizerValue value in localizationKeys.keys)
        {
            value.FileName = fullFileName;
            string key   = value.key.ToLower();
            bool   found = _keyValuePairs.TryGetValue(key, out LocalizerValue stringKeyValue);
            if (found && giveWarning)
            {
                Logger.Warning("Duplicate key:\"" + key + "\" value:\"" + value + "\" file:\"" + fullFileName + "\" existing:\"" + stringKeyValue.value + "\" file:\"" + stringKeyValue.FileName + "\"", LocalizerID.WARNING_DUPLICATE_KEY);
            }

            _keyValuePairs[key] = value;
        }
    }
    public static void ExportFile(string fileName)
    {
        // load original file
        string        fullFileName     = Localizer.FullFileName(fileName);
        LocalizerKeys localizationKeys = JsonReader.ReadJson <LocalizerKeys>(fullFileName);

        if (localizationKeys == default)
        {
            return;     // file failed to load
        }

        // collect keys
        int nKeys = localizationKeys.keys.Length;

        string[] keys = new string[nKeys];
        for (int i = 0; i < nKeys; ++i)
        {
            LocalizerValue localizerValue = localizationKeys.keys[i];
            keys[i] = localizerValue.key;
        }

        // export keys
        CreateKeysFile(fileName, keys);
    }