Hi,
for our application with are making it bilingue - supporting many languages.
Right now we are doing a tedious task which is transpose all properties in model for a resx where after it there is a tool we use to make translations.
Would it be possible to generate a resx file from T4 of dbcontext with name of entity and all it's properties?
How would I accomplish it?
Any help appretiated
Create resx with model properties
Re: Create resx with model properties
You can try using this template:
JIC: this sample shows a simple way to implement such scenario, you can modify and extend it in the way, that is most suitable for you.
Please tell us if this helps.
Code: Select all
<#
// template for Devart Entity Developer C# code generation.
// Copyright (c) 2008-2015 Devart. All rights reserved.
#>
<#@ template language="C#" #>
<#@ include file="Validation.tmpl" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Linq" #>
<#@ property name="Output" category="Output" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generation." #>
<#
// Settings
string baseFileName = model.FileName;
foreach (var cls in model.Classes) {
string rootFileName = cls.Name;
output.Extension = ".resx";
output.PushOutputRedirection(Output, "", rootFileName, OverwriteMode.Overwrite, BuildAction.EmbeddedResource, CopyToOutputDirectory.DoNotCopy, "ResXFileCodeGenerator", "");
#>
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<#
// Class properties
foreach (Property property in cls.Properties) {
#>
<data name="<#= property.Name #>">
<value>"<#= property.Type #>"</value>
</data>
<#
}
// Class navigation properties
foreach (RelationProperty relationProperty in cls.RelationProperties) {
#>
<#= relationProperty.Name #>
<#
}
#>
</root>
<#
output.PopOutputRedirection();
}
// End of generation
#>
Please tell us if this helps.
-
- Posts: 41
- Joined: Fri 12 Apr 2013 19:05