We're currently debating two strategies of localization:
A. Have an XML file for the structure of the business objects with a Localized key to a separate CSV file for the translation.
for eg. /Resources/Schema.xml
in a separate CSV file: we have all key/value pairs for the translations:
/Resources/Localized.txt
Model_Title, Title, Title (in French), ...
This way, when the structure changes, we just change XML once while the LocalizedKey's are in place.
B. Have separate XML files for each language based on Culture.
eg. have two files:
/Resources/en-US/US-Localized.xml
/Resources/fr-AU/AU-Localized.xml
This way, they will have same schema but separate files. Therefore the user would have to make sure that the schemas are the same as they would need to change it twice as opposed to Option #1 where they can just change it once.
However, the readability here is much better since the user would not have to track the key the make the changes.
What are your thoughts/ideas on the strategies I suggested?
Thanks,
It is not clear about the environment -- web? desktop? internal enterprise integrated something-or-other? Is there any particular reason you aren't using whatever i18n framework your tool chain supports (gettext, .NET resource files...)?
In general I'd say you want to separate out resources by culture (but to be honsest, fr_AU should be rare) to have better maintainability and do not have to load the entire file for all per-culture-versions in many situations. This is especially true if your number of supported languages/cultures goes into the dozens or more.
However, it would be important to accommodate XML schema changes. The XML could be auto-generated, from simpler structures (key-value, either in a database or files) and validated via a common schema.
This is whether (as commenters noted) you are providing localized products or customers can create their own localizations.
In general, you should consider existing tools, rather than start from the scratch.
In .net we are using Data Driven ASP.NET Localization
Resource Provider and Editor Created by rick strahl
Related
I m new to Umbraco, I have watched Umbraco.tv videos and want to use Umbraco in a project as a cms for managing and editing content. I am highly thankful for your guidance, time and for your thoughts on 3 questions:
How a Umbraco based data driven proejct should be architecutured ? For custom database tables do you use a separate database or same Umbraco database ?
How you work with custom data (non content) ? Do you make everything a document type, even if it is data which you are not going to create content of, for example a simple form submitted data ?
For DAL what technology or ORM you use ? Does Umbraco provide any API for saving simple data which is not a content or document type ?
Thank you so much once again.
1 The architecture question is important but it also has be considered against how complex the project needs to be.
I would usually recommend a separate database for non-Umbraco data since this keeps everything nicely independent and manageable especially as projects grow. It also means that CMS-specific data (i.e. content) can be kept separately from none-CMS data, e.g. user registrations.
However, if the project is small and isn't likely to grow, keep it simple. Use the same database and piggy back off Umbraco's implementation of the Petapoco ORM. For example:
ApplicationContext.DatabaseContext.Database.Save(new Thing());
Or
var item = ApplicationContext.DatabaseContext.Database.Single(thingId);
2 For custom data, again it's a matter of need, maintainability and simplicity. Only use document types for what needs to be and can be stored in the CMS. My personal rule is that if it isn't content or organises content then it doesn't belong in the CMS. For example news and news categories obviously belong in the CMS. However, the comments made on an article have no reason to in the CMS.
3 With regards to DAL, as I have said, Umbraco has an implementation of Petapoco that can be used out of the box. If the project is basic enough, just use that. There is little point in using anything else unless you need some separation and/or some additional grunt in which case I would recommend using NHibernate or EF.
In addition to the points above,
Use NuGet;
Use the MVC mode of Umbraco, as it will provide you with substantially more flexibility. Check out the Hybrid Framework as it provides a very good start point for a robust and flexible project architecture;
http://www.youtube.com/watch?v=0PtzyrEFG7I.
You always need a doctype in Umbraco, even if a page doesn't offer any WYSIWYG type editability
I would recommend using a Service Oriented Architecture, and the .dlls you drop into Umbraco can call the service. You can then deploy this service and have full control over how you do data access. Choose whatever method you want. Most modern sites use an ORM and it doesn't matter which, although nHIbernate and Entity Framework are the favourites. Don't be frightened to mix and match a more direct form of data access though as it can give you more control, especially in situations where performance optimisation of large queries is important.
If you're not familiar with adding custom .NET functionality into Umbraco, Trying out adding .NET user controls into Umbraco will give you a good start, and to help you to understand how you can utilise your own .dlls in Umbraco:
http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls.aspx
Anything custom I put in the same database as my Umbraco installation, but everything in custom tables. I don't touch the Umbraco tabes, I would not want to affect my future version updates.
Form submitted data I store in my own custom tables, I avoid creating content nodes with those, it's often tricky and doesn't give me the flexebility I often need. What I do instead is create an "Admin" document type, that is behind login (hard coded access, but easy to hook up to Umbraco users / members if wanted) and use my own custom UI to display my stored custom data.
I use PetaPoto (http://www.toptensoftware.com/petapoco/), it's a micro ORM that is added through a single file (installation is so easy then), using the same db connection string. Then I create custom models as I need and with with parts of the MVC. I normally stay away from route hijacking and rather use Surface Controllers and ajax calls for almost everything.
Hope this helps!
You can use the database containing the Umbraco tables for tables not used in Umbraco. If there are no hosting problems for you using multiple databases then you can simply link to a second database in the web.config - this would be safer than using the default Umbraco database as Umbraco packages often add database tables & there could be naming conflicts.
Viewing non-Umbraco data (eg from a database) is best done by adding macros that access the data using standard .Net patterns (eg razor scripts, .Net User Controls) & then in Umbraco you add in a reference to the macro in the template (view). You can use multiple templates (views) for any document type; so if you have a document type called 'forms' that contains no data you can use the 'allowed templates' checkboxes to say which view(s) are valid for this document type. When you add a content item you must specify a doc type at the start, but the template (view) can be changed at any time.
If you are storing data any .Net ORM will work with Umbraco (see http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software#.NET) I've used Linq to Sql, Subsonic & Dapper before now - but there are lots of options.
Take a look at my example using umbraco within Onion Architecture
https://github.com/afroukh/OnionCMS
Several of our apps use multiple databases from the example below - each in their own separate DBML file. The problem is, MVC by convention puts them all in namespace AppName.Models causing class name conflicts.
Which of the two options is the better fix and why:
1.) Putting them in separate namespaces. To keep stylecop/resharper happy, they would go in their own subfolder:
/Models
/Live
Live.dbml
LiveDataContext.cs
/Crm
Crm.dbml
CrmDataContext.cs
**but now in code, all uses of them have to be Live.Customer and Crm.Customer to differentiate between objects.
EDIT: The other main downside of this, is that I see no other sample code from experts that use sub folders in the Models folder. On top of that, in order to keep the same naming for Helper file code reuse - even apps that only use one database would need a subfolder in Models, which I certainly never see people doing in MVC
2.) Prepending all object names in one or both DBML designers with a prefix. This is my current approach. The Live database has Customer and Order objects, while the Crm database has CrmCustomer and CrmOrder. They all stay in the same namespace and /Models folder. This, however has two main drawbacks:
Quite a bit of prefix redundancy in accessing child objects: CrmCustomer.CrmOrders.First().CrmOrderType Marsha Marsha Marsha
In other apps which only use one database, we often omit the prefix - and then during code reuse or Helper files we have to do a lot of find/replace. This is particularly evident in Helper files that get added to every app like error/activity logging.
So I'd like to hear from other experts which of the two strategies they use, or something else entirely. It seems like a pretty common occurrence to have at least some name conflicts between databases. Thanks
Example table names:
Live Database:
Customer
Order
Address
Phone
Log
20 other tables
Intranet Database:
Customer
Order
Address
Phone
Log
20 other tables
CRM Tool Database:
Customer
Order
Address
Phone
Log
400 other tables
If I understand your problem correctly, you have two additional possible solutions:
You can modify the namespace of the entities generated by the DBML. Assuming you use T4 templates to generate them, you can right-click on the *.tt file, and go to properties. There is a namespace property that you can set to your own custom, and therefore unique, namespace:
MyCompany.MyProject.DataModels.Live
MyCompany.MyProject.DataModels.Intranet
MyCompany.MyProject.DataModels.CRM
A second, similar option would be to have each dbml and the generated classes be contained in their own project, and their own namespace associated with it. So in this case you would have three new projects:
Data.Live
Data.Intranet
Data.CRM
You would then add a reference to the projects when you want to consume them.
The benefit to this, in my opinion, is that it is very likely that tomorrow you could have a project that needs to reference Live, CRM, and a brand new database. In this case you would simply take a dependency on the projects you've already created (binary, or code -- my preference is binary, but YMMV), and that part of this 2nd project is complete.
In my opinion, do not decorate you classes (your option 2). That will be very difficult to maintain.
There is nothing inherently wrong with your option 1, and I have done that as well, but for most of my current solutions I create projects for the reusability factor.
So, I question the design that leads you to needing two identical databases in code. That aside, I think option 1 is better. Here is my reasoning:
The code is more reusable. If you ever need to seperate either model into another project, or remove one, you don't have to remove the prefixes anywhere. This offers clean separation.
Option 2 requires you to specify as well, you aren't avoiding this. However, if any class needs to access only one namespace, you only need to specify at the using level, and not in every single reference to the code. In classes that need both, you aren't avoiding the prefixses in either case. So option #1 wins out in the only case that matters.
I generally avoid type-prefixes as a rule. They are ugly.
Grumble, grumble, database design
We are writing an ASP.NET MVC application and every once in a while we need to add a string to a description or a note that is not generated by the UI to a database record. For example, if we need to reverse a transaction, we will prepend the word 'Reverse' to the description of the original transaction.
What is the best way to go about localizing these strings we have to add every now and again? On the web project we are using resource language files so everything is really taken care of by the .net framework. Can you get a class library project (the business layer) to take advantage of the automatic localization like a web project as well?
What we usually do is having additional resource files in the back-end projects. Usually they don't grow that big, so I think it's safe to do that. Usually, you can then access those resources like this:
string dummy = Properties.ResourceFileName.Reverse;
If you add a resource file in Visual Studio, the IDE will take care of generating the required code-behind to make that work.
For your example, I would suggest you having a string like this:
Reverse {0}
Then replace {0} with the actual transaction description. This way the translator will be able to move {0} before "Reverse" in case the specific language requires it. This is just an example, but best practices suggest us to avoid concatenating localizable strings as they may break in different languages. Example:
string dummy = string.Format(Properties.ResourceFileName.Reverse, transactionDescription);
I am currently working on a project that requires Static Text to be configurable(including labels, messages, and validation errors). I was wondering what the best approach would be. The app is being written using ASP.NET MVC and C# 3.5. I need all this static configurable text to be fed to the MVC project from a different project. I thought of using Global Resources, or using an XML file that would be loaded on application start. By the way, this is not about localization, also static text won't be configurable by the end-user.
You could use AppSettings and web.config as James answered. you could also store it in a database, with key value pair structure.
But you also need to get it from the configuration project to the ASP.Net MVC project. I would do it like this:
Create a service interface on the configuration project
use Enterprise Library Caching in the ASP.Net MVC project
Check if the value is cached
If not get it from the configuration and store it in the cache
I would probably make a separate project that contained a series of Resx files, these are pretty easy to work with and give you localization for free. This is where I would start and if you need to edit them on the fly through some admin tool then you could use something like Rick Strahl's data driven provider. This is probably a better approach then trying to come up with your own DB driven design.
I do agree that you probably need to clarify a bit of how and when the text will be editable.
Definitely stay away from the web.config and appsettings unless we are only talking about 1 or 2 lines of text. In general this is not a good idea for many of the reasons others have stated about app restarts and just general config bloat.
I would store it in the AppSettings section in the Web.Config file.
Localization is actually a decent way to handle this--it is solving the same problem, you'd just need to provide a single language file. Downside is that localization bits are not necessarily easily end-user editable. Which drives me to the fact that the real question to answer here is "how user editable is this information going to be?" If the answer is "frequently and easily" then you might want to make some sort of UI Snippets table in your database and handle it accordingly. Another decent option would be to use a custom configuration section and read/write to it using the configuration API. Also leaves open hand-editing XML files if need be.
I would use a XML file with a single load at the application startup
There are a number of questions on this site related to how to access RESX files in an ASP.NET MVC application, and best practices of using them.
However after reading (for the first time I might add) the MSDN article on resources I'm left wondering if there are even any advantages of using RESX files since I'm not going to be using server controls. Theres all this talk of 'implicit' and 'explicit' localization but I'm not going to benefit from that with MVC.
Ultimately my application will need string resources for buttons and menu items and also much longer HTML items for longer miscellaneous content. I would like to use a CMS for the longer items becuase I'm pretty sure I don't want to go sticking them into an RESX file.
Are there any compelling reasons to use or not to use ASP.NET resources in a new application. I'm going to assume that any future MVC enhancements or RESX enhancements will work in harmony together, but for now I'm just getting a glorified IDictionary as far as I can see.
Should I proceed with RESX or look elsewhere? Should I even be considering a CMS for the kinds of resources that RESX is designed for?
Any lessons learned would be appreciated.
There are couple of advantages to the RESX infrastructure:
you don't have to load the proper per-language resources. Once the locale of the thread is established, the CLr takes care of finding the appropriate assembly and loading the resources.
it is easy to hand off the locale-specific resources for localizations to third-parties.
there is a default fallback mechanism for non-localized resources.
There is also one particular disadvantage to the RESX approach:
it is hard to support translation model where the users translate your resources for you.
I'd like to elaborate a bit about that last point. Take for example the Facebook translation model. Facebook has fairly simple way for people to provide and vote on translations of various resources. If these are stored in a database, it would be possible to use them after the proper editorial process without rebuilding and redeploying the application. With the RESX model, the resources assemblies will have to be rebuild and redeployed, which could have high enough cost depending on the deployment process.
Thus, before deciding what localization process to use, I would look at the decision of who is going to do the localization and what the deployment process for the localizaed resources would be after the main application is already deployed.
EDIT: I forgot to mention that these considerations are orthogonal to the ASP.NET framework choice (MVC or WebForms).
I'd say "yes", resx files are still a good option for new applications. I don't think ASP.NET MVC in particular changes anything about storing your strings.
What's great about using resources is
they're pretty easy to manage
localizing your site is a much easier task than without resources (and I stress much easier)
you can replace the resource store at any time because resources use the provider model. You can switch out resx files for db entries without changing the implementation of your site.
I recommend resource files for the "site strings" which are different than the large blocks of data you might edit on a frequent basis. So for a full recommendation, I'd say use resource files (resx to start) for buttons, labels, etc, and a CMS for the meaty content.
If you are going to use Resx and not use Server Controls as you are in MVC, why not extend the MVC Helper methods so you can create localised labels and text? Then simply call the text from resource in the helper method.
e.g.
'<%=Html.CultureLabel("ResouceId") %>'
or
'<%=Html.CultureButton("Name","ResouceId", HtmlButtonType.Button) %>'
Just a thought.
Also managing globalisation of a site is MUCH easier with resx for the text.