public override List <StoredString> GetLocalization() { InlineStringsSet inlineStringsSet = this._inlineStringsRepository.Get(); return(inlineStringsSet.InlineStrings .Cast <StoredString>() .ToList()); }
public InlineStringsSet Get() { string inlineStringsFile = Path.Combine(LocalizationEditorEnvironmentManager.TempFolder, InlineStringsSet.INLINE_STRINGS_STOGARE); InlineStringsSet result; if (!File.Exists(inlineStringsFile)) { result = new InlineStringsSet(); } else { string json = File.ReadAllText(inlineStringsFile); result = JsonUtility.FromJson <InlineStringsSet>(json); } return(result); }
public InlineStringsRepository() { this._inlineStringsSet = this.Get(); }
public static void Generate(InlineStringsSet inlineStringsSet) { CodeCompileUnit compileUnit = new CodeCompileUnit(); CodeNamespace codeNamespace = new CodeNamespace("UnityLocalize"); CodeTypeDeclaration typeDeclaration = new CodeTypeDeclaration("InlineStrings") { IsClass = true, IsPartial = true, TypeAttributes = TypeAttributes.Public }; codeNamespace.Types.Add(typeDeclaration); compileUnit.Namespaces.Add(codeNamespace); foreach (StoredString inlineString in inlineStringsSet.InlineStrings) { CodeMemberField field = new CodeMemberField { Name = "_" + inlineString.Id, Type = new CodeTypeReference(typeof(LocalizableString)), Attributes = MemberAttributes.Private | MemberAttributes.Static, InitExpression = new CodeObjectCreateExpression(typeof(LocalizableString)) { Parameters = { new CodePrimitiveExpression(inlineString.Id), new CodeArrayCreateExpression(typeof(string[]), inlineString.Strings.Select(s => new CodePrimitiveExpression(s)).ToArray()) } } }; CodeMemberProperty property = new CodeMemberProperty { Name = inlineString.Id, Type = new CodeTypeReference(typeof(LocalizableString)), Attributes = MemberAttributes.Public | MemberAttributes.Static }; property.Comments.Add(new CodeCommentStatement("<summary>", true)); property.Comments.Add(new CodeCommentStatement(inlineString.Strings[0], true)); property.Comments.Add(new CodeCommentStatement("</summary>", true)); property.GetStatements.Add(new CodeMethodReturnStatement( new CodeFieldReferenceExpression( new CodeTypeReferenceExpression(typeof(InlineStrings)), field.Name))); typeDeclaration.Members.Add(field); typeDeclaration.Members.Add(property); } CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); CodeGeneratorOptions options = new CodeGeneratorOptions { BracingStyle = "C" }; using (StreamWriter sourceWriter = new StreamWriter(Application.dataPath + "/Plugins/UnityLocalize/InlineStrings/InlineStrings.generated.cs")) { provider.GenerateCodeFromCompileUnit(compileUnit, sourceWriter, options); } EditorUtility.DisplayDialog("Genaration complete", "Strings constants file generated!", "OK"); }