Override XML files

This is a forum to suggest new features for mojoPortal. 

This thread is closed to new posts. You must sign in to post in the forums.
9/1/2012 7:15:25 AM
Gravatar
Total Posts 182
Community Expert

mojoPortal Hosting & Design @ i7MEDIA!

Override XML files

Override standard xml files

Sometimes I want to change the wording used in mojoPortal for things like the headings above the blog categories or the text chosen to go above the "comments" section.

Instead of forking my code, is it at all possible to set up an "override xml" file, that I could add into my mojoPortal root and it would override the data in the xml file that provides this text? A link to the XML file used could be added as a key in the web.config, perhaps?

I know it's possible to change the text with jQuery and even CSS (:before pseudo selector and negative text indent), but I'd rather not do jQuery because if JS is disabled it won't work and not the CSS fix for semantic reasons.

This would be useful in a lot of places for people who are particular about text content.

Thanks for all your work with mojoPortal, it's a great CMS.
-Isaac

9/3/2012 4:37:31 PM
Gravatar
Total Posts 503
feet planted firmly on the ground

Re: Override XML files

Most (all?) of the texts are already controlled by resource files, allowing mojoPortal to be translated into any language. The same approach can be used to override the default texts, though you will need to remember to put back your modified files after upgrading.

See https://www.mojoportal.com/translatingmojoportal.aspx

For example you'll find blogresources.resx in the App_GlobalResources folder.

 

9/3/2012 7:12:58 PM
Gravatar
Total Posts 182
Community Expert

mojoPortal Hosting & Design @ i7MEDIA!

Re: Override XML files

Hi Crispin,

I'm already aware of that, I've been using it to change things. What I'm asking for is the ability to include an override .resx file so that I won't have to fork the code. Basically, it would be a single file that I could change all of the text resources in and it would not be overwritten by updates, only the originals would.

This is useful because after changing the default text on 40-50 different items around the site, it gets to be quite a pain to change them back on update. It's not super-important, but I am particular about wording, and I thought perhaps other people have the same problem. =]

It would be even more awesome if this was somehow capable of being included in a skin, that way when we're designing we can change things to make them match the design a bit better. Not sure if that's possible though.

Thanks for your response,
-Isaac

9/4/2012 2:38:00 PM
Gravatar
Total Posts 18444

Re: Override XML files

Hi Guys,

The .resx files are intended for localization and I don't know of a good way to allow overriding any/all the resource strings, but I do agree that we should have a way to override some specific labels. While this could be done by editing the .resx files after each upgrade, I think for specific labels a better solution can potentially be provided on a case by case basis so I'm open to hearing about specific labels that your customers ask you to change most often.

For example in the blog we do already have a way to override the category labels (except for one I just discovered as a bug). The highlighted settings below allow these labels to be changed from theme.skin:

<blog:BlogDisplaySettings runat="server"
UseBottomNavigation="true"
UsejQueryCalendarNavigation="true"
HideCalendar="false"
HideFeedLinks="false"
HideStats="false"
BlogViewUseBottomDate="true"
BlogViewHideTopPager="false"
BlogViewHideBottomPager="false"
ArchiveViewHideFeedbackLink="false"
HideTopSideBar="false"
HideBottomSideBar="false"
OverrideListItemHeadingElement=""
OverrideCategoryLabel="Tags"
OverrideCategoryPrefixLabel="Posts Tagged in:"
OverridePostCategoriesLabel="Tagged In:"
PostListForceExcerptMode="false"
PostListForceTitleOnly="false"
PostListUseBottomDate="true"
PostListDisableContentRating="false"
DetailViewDisableContentRating="false"
UseBottomContentRating="true"
DisableShowCategories="false"
DisableShowArchives="false"
DisableShowStatistics="false"
/>

except OverrideCategoryLabel is not working in the latest release as I just discovered when looking into answering this post. I just fixed it in my copy and in the source code repository so it will be fixed in the next release.

Also note that UsejQueryCalendarNavigation is a new setting not yet in the current release but it is working in the latest code and will work in the next release. It allows using the jqueryui datepicker for the date navigation as an alternative to the asp:Calendar control used by default, so don't add that one yet unless working with the very latest code from the repository and note that enabling that may require other css changes to make the jquery calendar fit in the column without overflowing.

So rather than suggesting a technical solution like a way of overiding all the xml/resx files, instead I would rather hear which specific labels your customers are asking about the most to be able to customize and we can look into adding specific overrides for those in theme.skin.

Best,

Joe

9/4/2012 3:04:45 PM
Gravatar
Total Posts 503
feet planted firmly on the ground

Re: Override XML files

Some modules have a LOT of labels, so isn't there a danger this becomes very unwieldy? Also, how does it interact with the multi-language resource files? Does the override beat the resx, regardless of language? Can the overrides cope with multiple languages?

I'm thinking that changing labels is really the same thing as localisation... i.e. it is adapting the presentational description to use the words that best match the cultural and linguistic world view of the admins and users. So your "Tagged in:" might be my "Indexed as:". Both "en", but both legitimate localisations.

If this is valid, then could we look for a way of allowing the localisation to persist through upgrades? The skin is a good place for this as Isaac suggested.  So, could this be achieved by a setting at the site level along the lines of "Use skin-specific resource files?" = true/false.  If true, then when rendering any feature, we look into the skin folder (or a resources subfolder) for the relevant setting in the resx file, and fall back to the normal files if not found.

This would allow me to change every label in a way that survives upgrades, and works across all languages. If an upgrade adds new labels, it will still work as it will fall back to the default.

(PS I'm feeling something similar could work for email templates, which are also blown away by upgrades, and frequently need customising).

9/4/2012 3:12:56 PM
Gravatar
Total Posts 18444

Re: Override XML files

If we implement overrides it will be on a case by case basis I will not be doing it for lots and lots of labels. If you really need to change lots and lots of them then you can just keep editing those .resx files as in the past so be judicious in suggesting which labels you'd like to be able to override.

If an override is used it will not be localized it will be customized. Most people are forcing a specific language if they are creating sites for specific languages. If a site's content from  the database is in a single given language then there really is not a lot of benefit for some labels and button text to be localized so I don't see it as a big deal, its no different than database content which is not localized.

9/4/2012 5:38:38 PM
Gravatar
Total Posts 182
Community Expert

mojoPortal Hosting & Design @ i7MEDIA!

Re: Override XML files

Hey guys,

Thanks for looking into this. Joe, my idea was mostly for design purpose, and it's not especially important. I was just asking to see if an easy fix could be found, but if not I'll only change the .resx files on my site and I'll just keep a copy of them for upgrades.

The value of changing labels is small but significant in my opinion. Mostly because users are accustomed to seeing specific text in specific places - when they see a form, they're expecting some kind of "submit" button, but I don't want the wording to be that bland. So instead, I often want it to say "Proceed" or something of that sort. Or above blog comments, instead of the heading just saying "Comments", I'd like it to say "Share your mind" - something that fits with the writing style of the rest of the content on the page.

It's kind of a supplement for designs, but I think it can make a site more friendly and more unique simultaneously. Like I said, it's not extremely important though. But if you ever come up with a way to do it without forking the code, please let us know.

Thanks,
-Isaac

9/5/2012 7:45:45 AM
Gravatar
Total Posts 18444

Re: Override XML files

Hi Isaac,

The specific labels you are mentioning are all ones I would be willing to add override properties for in theme display settings.

What I'm trying to say is.

1. a way to overide any and all labels from theme.skin is not feasible

2. for a limited set of specific labels that may reflect the personality of the site I agree it would be nice to be able to override them and I'm open to those suggestions and willing to add displaysetting properties for them on a case by case basis. So for those specific labels that you feel are important to site personality, feel free to make the case for them and I will consider them on a case by case basis but it definitely is not going to be lots and lots of them from any and all features. The ones for comments do make sense but that doesn't mean that it will make sense in all features. I'd like to satisfy common needs but I'm not going to scratch every possible itch.

3. overriding is choosing customization over localization, you can't really have both and trying to achieve that would be stepping into a technical monstrosity so I'm not willing to go there especially because it doesn't really add much value to try to achieve both since the main content form the db is not localized. Its relatively easy to do it for a limited set of labels but not feasible to do it in a global way.

Best,

Joe

 

9/5/2012 8:08:33 AM
Gravatar
Total Posts 503
feet planted firmly on the ground

Re: Override XML files

Hi Joe

Is my idea above technically impossible? (i.e. it is not possible to pull in resx files from an "override" location, perhaps in the skin).

I've not tested it out, but this post perhaps suggests that the location asp.net looks for the resx files can be changed dynamically http://stackoverflow.com/questions/1649226/how-to-dynamically-load-and-switch-the-resource-file-in-the-web-app-asp-net-wi

but I don't know whether this is feasible in reality (i.e. look in the override location then falling back to the default if the resx file wan't there or didn't contain the right labels).

If it is possible somehow, then it would achieve what me and Isaac appear to want, and mean you would not have to keep adding individual labels into theme.skin overrides.

9/5/2012 9:39:22 AM
Gravatar
Total Posts 18444

Re: Override XML files

.resx files can only live in the /App_GlobalResources folder (or /App_LocalResources which we don't use in mojoPortal), there are ways around that with VirtualPathProvider but its just a lot of uneccesary overhead and complexity.

I'm not claiming its impossible to implement a global override solution I'm saying it would be overly complex and therefore not feasible enough that I'm willing to go there. It would be a big mess in my opinion and likely to lead to performance problems.

For example in that post on stackoverflow the question was about storing labels in the database. I don't want hits to the database for every label, its a bad idea. And the suggested solution is just a way to manually load a resource file from a specific location but that kind of code would require very extensive changes and have to be implemented all over the place and the example doesn't account for missing files or missing keys within files which cause null reference exceptions and basically replacing/bypassing the built in language fallback of resx files which is part of the asp.net framework and not something I want to build a replacement for. I'm not going there, it is a path to building a monstrosity. It is not worth it and not needed in my opinion. 

 

 

 

9/5/2012 10:26:01 AM
Gravatar
Total Posts 18444

Re: Override XML files

Consider that the built in localization support of the ASP.NET framework is awesome.
By storing the files in the /App_GlobalResources folder I get strongly typed objects to set my labels like this:
litHeading.Text = BlogResources.BlogCategoriesLabel;

I don't have to do anything to make it localize, by default the thread will execute as the culture specified in the browser preferred language and it will automatically choose the correct .resx file if it exists (or by config settings you can force it to execute as a specific culture), so if my browsert is set to de-DE for German and BlogResources.de.resx exists it will use that and if the key "BlogCategoriesLabel" does not exist in that file it will fall back to the default English file. I get all that for free, no hunting around the file system no checking for missing files or keys needed in my code and the key must exist in the defualt file for it to compile so errors are avoided.

Similarly there is a databinding syntax like this:
<asp:DropDownList ID="ddGMapType" runat="server" EnableTheming="false" CssClass="forminput">
<asp:ListItem Value="G_NORMAL_MAP" Text="<%$ Resources:Resource, GoogleNormalMap %>" />
<asp:ListItem Value="G_SATELLITE_MAP" Text="<%$ Resources:Resource, GoogleSatelliteMap %>" />
<asp:ListItem Value="G_HYBRID_MAP" Text="<%$ Resources:Resource, GoogleHybridMap %>" />
<asp:ListItem Value="G_PHYSICAL_MAP" Text="<%$ Resources:Resource, GoogleTerrainMap %>" />
</asp:DropDownList>

again I don't have to do anything extra to make it localize.

Now do I want to throw that away and build my own thing that I have to support? NO!!!! That would be a lot of work and a huge re-write of good solid working code.

But on a case by case basis I'm willing to do things like this:

if (displaySettings.OverrideCategoryLabel.Length > 0)
{
litHeading.Text = displaySettings.OverrideCategoryLabel;
}
else
{
litHeading.Text = BlogResources.BlogCategoriesLabel;
}

9/5/2012 2:50:22 PM
Gravatar
Total Posts 503
feet planted firmly on the ground

Re: Override XML files

I completely agree with you there Joe - my hope was that ASP.Net might itself provide a way of prioritising/overriding resources, in the same way it falls back from a language file to the default. Clearly not!

Also I assume it is not possible/desirable to move such files around at runtime (from an override location to the App_GlobalResources folder)  - I think that causes the site to recompile?

So your solution is as good as we can get - either we edit the resx files and put them back after upgrading*, or use theme.skin and suggest labels that need overrides.

* to make this easier, is there a case for a different download package, one that contains changed files only?  This would make my life much easier with custom email templates and resx files. Could save LOTS of time when upgrading many sites with different customisations.

9/5/2012 3:12:27 PM
Gravatar
Total Posts 18444

Re: Override XML files

I don't want to try to keep track of which files were changed, that is to much burden that would slow down progress and make myself and other devs reluctant to make changes for beaurocratic reasons and it is likely that I and others would fail at that and forget some of the files that changed. During upgrade users should assume all files were changed, otherwise it is very likely that strange hard to diagnose bugs will happen if people don't update all the files that need to be updated. I think some people have used diff tools to do that occasionally but I think the safest bet is to update all the files. I update all the files when upgrading my own sites.

Note that you should not replace a .resx file with an older version or you may end up with missing keys that were added to the new one, so unfortunately you must re-edit any changes you make to new .resx files.

Therefore I would be very judicious about which labels you promise to change for your customers to keep that to a minimum and work with me to make the case for the ones that really really need to have an override option because they are so commonly requested to be changed by customers for valid reasons that make sense. Some customers will ask for all kinds of things that are not really reasonable so its a judgement thing and I think sometimes pushback is needed for the customer's benefit to avoid those maintenance issues with resx files.

.resx files are indeed compiled by the asp.net compiler into classes behind the scenes at application startup, that is why we started shipping most additional languages in a separate download to reduce the amount compilation. But there is not a good way to put them in other places, the designated location of /App_GlobalResources is a special asp.net folder and is what makes it possible to have strongly typed resource objects that provide intellisense and make it trivial to localize strings. As soon as we add a new key in the resx file we get intellisense for the new key in code. We can always wish for more magic but it really is already doing a lot of heavy lifting for us already so its best to work with the grain of the existing localization framework built into asp.net rather than work against the grain and make it more complicated.

Best,

Joe

9/5/2012 3:23:13 PM
Gravatar
Total Posts 1991

Re: Override XML files

I use WinMerge to copy over my changes to .resx files. This works very well and I haven't run into any issues with it.

The scripts I use for updating all of our mojoPortal sites use robocopy for copying over the "changed" files. I put quotes around changed because often times nothing has really changed in the file but it was opened and saved at some point so the date/time stamp changed so the file appears to be different. 

9/5/2012 3:39:23 PM
Gravatar
Total Posts 1188
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Override XML files

Hey Joe, would you be willing to share your robocopy site update scripts? I think a lot of people would find them really useful.

Jamie

9/5/2012 3:52:01 PM
Gravatar
Total Posts 1991

Re: Override XML files

I'm working on rewriting them with PS so once I do that, I'll share them. You may want to check out Shuan Geisert's post "Automatically Upgrading mojoPortal Using PowerShell" over at the CODE Colorado State University website.

Thanks,
Joe D.

9/5/2012 5:46:53 PM
Gravatar
Total Posts 182
Community Expert

mojoPortal Hosting & Design @ i7MEDIA!

Re: Override XML files

Joe, your answer gave me an idea.

Basically, the code already reads a different language file and resolves to a default file if the key isn't found in the other language file. This is the functionality we need, so it begs the question - is it possible to sort of 'fool' the code into thinking you're using another language file?

If so, we could make our own language file that's really just an override file, then declare what language we want the site to render in, and it would read that file first, render any keys given there, and then check the default file for keys that are missing. This way we could only change whatever labels we wanted and wouldn't need to update the file with mojo.

The main thing I think we would need is a way to declare our 'language' in the web.config or something, such that it tells the code to look for that language's xml file first.

I don't understand the code behind mojoPortal very well, so please forgive me if this is a stupid question.

Thanks,
-Isaac

9/5/2012 6:37:49 PM
Gravatar
Total Posts 18444

Re: Override XML files

Hi Isaac,

That is good out of the box creative thinking! I'm not sure how feasible it is, you'd have to implement a custom cultureinfo class and plug it in somehow to the .net framework, but it did make me remember reading a blog post where someone was trying to do that for Klingon, with a quick google I found something about that but probably you would need to do more googling and research to determine how feasible it is.

But from a quick glance I'm not sure its possible without code changers in mojoPortal, it all depends on if you can plug in a new culture info class directly without needing changes in mojoPortal.

From a quick read it sounds like it would require changing all use of culture info to use some other custom class that inherits from culture info base class, but maybe changes in the .net framework over time have made it possible. I just don't know without more research.

Best,

Joe

 

9/5/2012 6:52:24 PM
Gravatar
Total Posts 18444

Re: Override XML files

Actually the more I think about it the more clever and brilliant that idea seems.

Skip the Klingon and choose an obscure langauge that we don't support and aren't likely to. Create .resx files for that language that only have the things you want to override then force it to use that culture. Technically you could use any language that you don't care to support in your site and for which you are not deploying the resx files we ship even if it is a supported language, but safer to pick something more obscure.

Fanatastic creative idea Isaac!

Best,

Joe

9/5/2012 6:56:19 PM
Gravatar
Total Posts 18444

Re: Override XML files

Here is a list of languages supported by .NET as of version 2 there is probably a more up to date list somehwere/, by choosing one of those you don't have to implement any custom cultureinfo, just pick one we don't support and give it a try and let us know how it goes.

Best,

Joe

9/5/2012 7:29:47 PM
Gravatar
Total Posts 182
Community Expert

mojoPortal Hosting & Design @ i7MEDIA!

Re: Override XML files

Alright, I've managed to get this working on my site.

I decided to use Konkani because it's at the bottom of this list.
Steps are as follows:

  1. Duplicate the resource file you want to change. I changed blogresources.resx in my case.
  2. Rename the file to use the language extension you want, as found in the link Joe shared.
  3. Open the user.config and add your override code as found here. In my case I added two keys:
    <add key="UseCultureOverride" value="true" />
    <add key="site1uiculture" value="kok" />
    It is important to note that you should probably only use the uiculture for this, so your date and time format strings aren't changed.
  4. Change your new resource file to include what keys you want. It is probably a good idea to remove all of the keys except for the ones you want to change.

A really great aspect about this method is that mojoPortal already supports using different cultures for each site in your mojo installation, so it makes it easy even if you have multiple clients on the same install or if you want to use different text for your own different sites.

Thanks again Joe, this will work well for me I think.
-Isaac

9/5/2012 10:24:36 PM
Gravatar
Total Posts 1991

Re: Override XML files

Hey guys,

Great idea Isaac. 

One question for Joe, does forcing the culture have an effect on dates or currency?

Thanks,
Joe D.

9/6/2012 12:51:54 AM
Gravatar
Total Posts 503
feet planted firmly on the ground

Re: Override XML files

According to the documentation here, dates or currency are unaffected if you only set <add key="site1uiculture" value="kok"/>

They become fixed to Konkani formats (!?) if you set the <add key="site1culture" value="kok" />

I like this solution, with the only negative being that it blocks the real localisation. But as Joe has pointed out above, since we have no way of localising the database content perhaps this is no big deal. I'm hoping in due course that this functionality may be developed (i.e. method of localising database content e.g. ability cloning a feature instance and specifying a language tag for each sibling), but that's another thread!

Of course we'd need to ban any true localisation attempts by the 7.4 million Konkani speakers ;-)  so, as the language of choice for label overriders I'm preferring "fo-FO" Faroese - Faroe Islands, an insular Nordic language spoken by about 45,000.

9/6/2012 10:47:36 AM
Gravatar
Total Posts 1188
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Override XML files

Maybe Sanskrit "sa" would be a good choice. Some seem to consider it about as "dead" as Latin, and although there have been attempts at revival, I can't imagine anyone will want to start providing resx files for it in the future.

9/6/2012 4:15:16 PM
Gravatar
Total Posts 18444

Re: Override XML files

The only limitation for this technique is it can only be relied on if English is the default fallback.

It is possible to force a different language as the default from web.config <globalization element, but if you change it there to a language that has any missing keys or files it will cause null reference errors. The only language we have where the resx files are guaranteed to never be missing any files or keys is English.

So for example if I'm forcing my site to French using:

<add key="site1uiculture" value="fr-FR"/>

then I need to keep English as the default so that no errors can happen.

Therefore if I'm forcing the site to use French already I cannot also force it to use another language resx files for overrides.

If I made sure that there were no missing keys or files for French, then I could set the default to French in the <globalization element, and then I could force the site to use a different language and take advantage of this technique. So it isn't impossible, if anything it may encourage more help with keeping translations up to date. (Too bad about Ammanuens going away I wish there was something else equivalent but don't know of anything).

Still this technique can be used by lots of people and it is pretty clever. I will compile the info from this thread into a documentation article soon and give credit to Isaac for the great idea.

As far as which language to override, it only matters whether its a language you might ever care to support in your own site. Since additional languages are downloaded separately it really only matters whether it would ever conflict with a language whose resx files you did want to deploy.

Although recommending a specific one in the article might be fun, like if we use Konkani we could dub this technique the Konkani technique or the Sanscrit technique which might be catchy ;-D

But another idea is to force a variant of English that we won't likely ever have resx files for like en-ZE which is the Zimbabwe variant of English, and if we get visitors from Zimbabwe on our site chances are they will be able to read it just fine anyway.

Definitely the override resx files should only contain the keys you are actually overriding in any case, that way if something changes for an existing key that you are not overriding you will get it from the default English files. Also I think that makes it easier to manage because you know exactly which keys you are overriding when you open one of those files since there are not any keys in there that you are not overriding.

Best,

Joe

9/19/2012 2:59:55 PM
Gravatar
Total Posts 18444

Re: Override XML files

I finally got around to creating an article based on the ideas from this thread.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.