예제 #1
0
 public static void I18nWarningMessage(StringBuilder builder, OutputLanguage outputLanguage)
 {
     if (outputLanguage == OutputLanguage.enUS)
     {
         return;
     }
     builder.AppendLine($"// Outputting to the language {outputLanguage.ToString()}.");
     builder.AppendLine($"// Not all languages are tested. If a value is not outputting correctly, you can change");
     builder.AppendLine($"// the keyword info in the Languages/i18n-{outputLanguage.ToString()}.xml file.");
     builder.AppendLine();
 }
예제 #2
0
        static void Main(string[] args)
        {
            string[] samples =
            {
                "FunctionalityTestShader.cs",
                //"SampleShader.cs",
                //"SampleTextureShader.cs",
                //"MoltenSpriteShader.cs"
            };

            Translator        translator = new Translator();
            TranslationResult output     = null;
            OutputLanguage    language   = OutputLanguage.HLSL;

            // Load all of the sources into a dictionary,
            // so that all of them can be translated in a single converter.Convert() call.
            Dictionary <string, string> sources = new Dictionary <string, string>();

            foreach (string fn in samples)
            {
                Console.WriteLine($"Reading {fn}");

                FileInfo fInfo    = new FileInfo(fn);
                string   strInput = File.ReadAllText(fn);
                sources.Add(fn, strInput);
            }

            output = translator.Translate(sources, language);

            // Store the output to file so we can take a look at it ourselves.
            if (output != null)
            {
                string langExtension = $"{language.ToString().ToLower()}";

                foreach (KeyValuePair <string, ShaderTranslationResult> kvp in output)
                {
                    using (FileStream fs = new FileStream($"{kvp.Key}.{langExtension}", FileMode.Create, FileAccess.Write))
                    {
                        using (StreamWriter writer = new StreamWriter(fs))
                        {
                            writer.Write(kvp.Value.SourceCode);
                        }
                    }
                }
            }

            Console.ReadKey();
            translator.Dispose();
        }
예제 #3
0
        public static string Translate(OutputLanguage language, string methodName)
        {
            if (language == OutputLanguage.enUS)
            {
                return(methodName);
            }

            lock (LanguageLock)
            {
                if (CurrentLanguage != language)
                {
                    throw new Exception($"The '{language.ToString()}' language is not loaded.");
                }

                return(Language.Methods.FirstOrDefault(m => m.EnglishName == methodName)?.Translation
                       ?? throw new Exception($"Could not find '{methodName}' in the language file."));
            }
        }
예제 #4
0
 private void Start()
 {
     m_Dropdown.captionText.text = m_OutputLanguage.ToString();
     m_Dropdown.SetValueWithoutNotify((int)m_OutputLanguage);
     m_JSONLoader.Load();
 }
예제 #5
0
        public static void LoadLanguage(OutputLanguage language)
        {
            lock (LanguageLock)
            {
                if (CurrentLanguage != language && language != OutputLanguage.enUS)
                {
                    string        languageFile = Path.Combine(Program.ExeFolder, "Languages", "i18n-" + language.ToString() + ".xml");
                    XmlSerializer serializer   = new XmlSerializer(typeof(I18nLanguage));

                    using (var fileStream = File.OpenRead(languageFile))
                        Language = (I18nLanguage)serializer.Deserialize(fileStream);
                }
                CurrentLanguage = language;
            }
        }