开发者

Storing formatted text in Resource File .Is it Possible?

开发者 https://www.devze.com 2023-03-13 09:19 出处:网络
Building an asp.net mvc website that has to be multilingual and wondering if it\'s possible to store formatted text in a resource file and whether it makes sense.

Building an asp.net mvc website that has to be multilingual and wondering if it's possible to store formatted text in a resource file and whether it makes sense.

Lots of pages are static and user can edit them and add their own formatting "Bold,italics etc.." and was wondering what is the best way to approach it.

I dont want to crea开发者_Python百科te one page x language and storing in the database involves creating a structure to handle the same info in multiple languages.Seems hard to maintain.

Have you done it before? How did you do it

any suggestions Thanks a lot


Is it possible?

Certainly.

Does it make sense?

It depends. I would not recommend resource files (via ResourceWriter) for storing dynamic content.

Your problem

Let me rephrase it (I am not sure if I understood you correctly). You want to give your users an ability to change presentation style. User will be able to change the style and that change would be somehow propagated to whatever languages the content is translated to.

In such case, I see some issues:

  1. How to match English contents with translated one?
    It is typical for translation to have different order and possibly different number of sentences. There is no way to match them unless...

  2. Storing such information in resource files along with translatable strings would result in something that is hard to maintain. I believe you would need to either add formatting tags or content tags with styling information in order to achieve that. The result would be a mess; hardly readable, as tough to modify.

OK, so what can you do? Actually, what I could recommend is to create Customization Mechanism for CSS files. In your case you need:

  1. Provide CSS classes as well as unique identifiers (HTML id attribute) to each structural elements (tags if you prefer), so that you have something like <div id="main" class="main"><p id="p1" class="normal">.... The id's will give users an ability to target precisely that element leaving others untouched (via #p1.normal { // definition here }).
  2. Store CSS in the Database and create some editor for users.
  3. Create a Handler to serve CSS from database upon web browser's request.

Even with such solution you won't avoid some problems. One is that you need to actually alter font family while translating into certain languages, so you might need language-based CSS files. Another problem pops up when user wants to put bold attribute on certain word - with such solution this is not possible (but to be honest if you want to allow that, this won't be i18n friendly for the reasons I mentioned earlier).
BTW. Bold fonts should be avoided for some languages. For example Chinese characters are pretty hard to read if you manage to output them with bold font.


If your users can post in multiple languages - its probably best to use a database to store the info and accompanying formatting. If it is for labels and other static text on the website - the resource files are a good solution. The resource files store the content as strings - but storing formatted text in there breaks the 'seperate the presentation from the logic' idealogy.

0

精彩评论

暂无评论...
验证码 换一张
取 消