Module Localization in DNN - localization

I don't know much about the localization process in DNN. The question is that how can you localize a new module?
Is it possible to include localization files with every module separately? What solutions can you come up with?

Localization of a module is pretty easy thanks to DotNetNuke.
Wherever your .ascx (View) file is, the App_LocalResources folder should always accompany it, on the same level. There should also be a corresponding .ascx.resx file in that folder.
view.ascx
App_LocalResources
- view.ascx.resx
Once you have that structure in your module. DNN will pick the file up immediately.
To use that resource strings in the resx. Simple tack on the ResourceKey property to the end of your asp controls. e.g.
<asp:Label ID="lblExample" runat="server" ResourceKey="lblExample" />
You should have a lblExample.Text in your resx file which matches up with that label. Note that it adds .Text to it automatically.
If it's not showing up, there are a few things to check
LocalResourceFile property in code. What location is it pointing to?
set ShowMissingKeys=true in web.config and you'll see what resource strings you're missing.

Please find this document. I am not sure if it covers your questions and how localizing DotNetNuke modules is different from other Asp.Net applications but please try it out.
If I may suggest something, I would add more tags in the future (like C# for example), it will be visible to broader audience which may result in better answers.

Simply create a folder called "App_LocalResources" on the same level as your .ascx view files in your project. For each file that you want localized, simply add a .resx file with the same name as the view (including the .ascx extension).
Resx Name Example:
"View.ascx.resx"
Using localistion is really easy after that. Simply set the Resource Key property of whichever controls you want to pull from your resx file to a meaningful name
Example:
<dnn:Label id="lblName" ResourceKey="lblName" runat="server" />
Resx File:
"lblName.Text" will assign to the Text property of the label
"lblName.Help" will assign to the DNN Tooltip property if you are using dnn:Labels like above
If you want to start using DNN Labels simply put this tag at the top of your page.
<%# Register TagPrefix="dnn" Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.UI.WebControls" %>
<%# Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
Another handy method available is:
LocalizeString("key")
It will pull from your resource file and it quite handy when working with things like email templates.

Related

What does #Html.Sitecore.Placeholder() point to?

In Sitecore 7 MVC, my understanding is that partial views are represented by using Razor declarations such as #Html.Sitecore().Placeholder("some_thing") in a .cshtml file.
In this context, what does the argument "some_thing" actually represent - is it something located in the Sitecore instance? If so, how can I locate the thing that "some_thing" represents within the Sitecore database?
In the shortest way: Sitecore Placeholder is a place where you can add your components.
The argument some_thing in #Html.Sitecore().Placeholder("some_thing") is the name of the placeholder.
You can have multiple placeholders on your page. When you add a component to a page, you tell Sitecore "Put in in placeholder some_thing and that's how Sitecore knows where to place it.
Read Presentation Component Reference for more information (yeah this document is years old, but the idea is still the same).
#Html.Sitecore().Placeholder("some_thing") is typically in a layout page such as your DefaultLayout page. Like Marek said it is a place that you put components. If you log into Sitecore and look into at a page, under the Presentation tab, there is an icon that says Detail. Click that. A pop-up will open (I think it still did in version 7, I dodn't have an instance running. On that popup, select a component or add a new component to the Default Layout. In the settings for the component will be a field called Placeholder. Put the text "some_thing" in there without the quotes. I think this is what you are asking what this is the placeholder representing.

How to change URL names in Umbraco

This is my first time round using Umbraco and I have created Document Types / Pages using the wrong naming format and now this has transpired into my page URL's, for instance /about-page/. How would I go about changing them to /about as I have searched the back-end admin panel and there dose't seem to be an option to change their link to document values.
Would anyone be able to provide a simple code based example using umbracoUrlAlias or umbracoUrlName how I could change this preferably in Razor.
Thanks
Editing #run yards Solution by digbyswift help in comment
Correct Solution:
Create Property on in Document Types which applies to all pages you want to change the URL
Call the name anything you want e.g Page URL and Possibly give it a new tab.
Call the alias umbracoUrlName
Type as text sting
Should not be Mandatory (As when you start replacing .Url with .umbracoUrlAlias within the views it will need to be present)
Tab as Generic
Click Save on top right on the page
Added screenshot for starter kit on Umbraco v7.2.5
Unless I'm very much misunderstanding your issue, you should just be able to change the name of your page and republish. This doesn't need an additional field, just change the value in the "Properties" tab and republish the page. This will automatically change the URL of the page.
You can also create a property called umbracoUrlName using a TextString property editor. If this has a value then it will generate the URL fragment for the page using this value, rather than the page name. This changes the URL for the page, rather than creating an alias, like umbracoUrlAlias.
Solution:
Create property on in Document Types which applies to all pages you want to change the URL
Call the name anything you want e.g Page URL and Possibly give it a new tab.
Call the alias umbracoUrlAlias
Type as text sting
Make it required (As when you start replacing .Url with .umbracoUrlAlias within the views it will need to be present)
Go into all your pages and rename them using the property you just created
Now with your code, say with the navigation where you have used .Url change it to .umbracoUrlAlias and the new URL's will be used.
Note if you don't use .umbracoUrlAlias the links will still be active i.e. they work but they won't be displayed in the address bar as .Url spits out the original ones associated with the page.
You can apply on URL names in web.config:
In section find:
<add key="umbracoUseDirectoryUrls" value="false" />
this will set url names for new created items to name.aspx
If you set this to 'true' then new items will be named like /name/
Additionaly you might want to avoid of Handling some urls by Umbraco pipline, just use this setting - add URLs which must be bypassed:
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd" />

How to force a specific uiculture using web.config in MVC

I have added Resource.fr-FR.resx to my project and have done the globalization setting in
web.config as follows.
<system.web>
<globalization culture="fr-FR" uiCulture="fr"/>
</system.web>
that is all you need according to http://msdn.microsoft.com/en-us/library/bz9tc508%28v=vs.80%29.aspx
but when I run my app it is still in english
I have checked "Thread.CurrentThread.CurrentUICulture" in Application_Start() and it says FR.
what am I missing?
the same thing has been posted in
MVC 3 Setting uiCulture does not work
but no answers.
Culture is not the same thing as Language. A "culture" is a set of formatting rules for dates/times, currency, calendaring, and a few other things (like text Title Casing rules).
Setting a culture will not automatically localize your application (where localization is when all of the human-readable strings are translated into another language, such as French). Localization and UI translation is a long, painful and expensive process. ASP.NET does not do it for you.
If you want to localize your application, you need to ensure that all human-readable strings are stored in a resource file (.resx in .NET) and you have created "satellite assemblies" that contain translated strings for other languages. You then need to ensure that ever string displayed to the user in your application uses the Resources APIs (or IDE-generated helper classes). This is painful because it means going from this in your *.aspx files...
<p>Hello, welcome. This is in English.</p>
...to this:
<p><%= Resources.WelcomeMessage %></p>
...or this (if you have too many strings to be managed by the Resources helper class):
<p><%= ResourceManager.GetString("HomePage_WelcomeMessage") %></p>
...doing this, of course, breaks any visual-designers for your website, for example.

Share a razor declarative helper between multiple mvc web projects

Let's say I have 2 MVC web projects (web1 and web2) and 1 project containing shared views (common) (using the razorgenerator of David Ebbo)
web1 and web2 both have a test.cshtml file. Several blocks of code in both test.cshtml files are exactly the same.
I'm trying to find out if it's possible to share a declarative helper (#helper) between several cshtml files which are in DIFFERENT projects. So putting a cshtml file in my App_Code does not help (I would need to have 1 in each web project, which is obviously not what I want).
I know I could create a bunch of shared partial views in my 'common' project, but it seems kinda overhead to create 20 cshtml files that each contains a very small portion of html.
I know I can create a standard helper method (static string GenerateAPieceOfHtml(this HtmlHelper helper, ....)), but there I loose the ease of writing html as you can do it in a cshtml file.
For a short while I thought I bumped into an answer that would allow me to do it. But as I wrote in a comment, that code did not compile for me.
I hope my question is clear :)
[Update]
As csharpsi asks in a comment.. I did try out the code from the other post, but it did not spit out any HTML for me. Since I started to think that that answer should probably do the trick since it has 13 upvotes, I decided to give it a second try..
Again I didn't get any output, but then I tried it a little bit different.. and success!
I was trying this (which doesn't spit out any html on the page):
#{ new Test().DoSomething(Model); }
This is the version that DOES WORK:
#{
var html = new Test().DoSomething(Model);
#html
}
Other version that works:
#(new Test().DoSomething(Model))
What should I do with this question? Delete it? Write an answer myself?
Why are you trying to use razor helper for this anyway ? Razor helpers are one-particular-viewengine hack, your application shouldnt rely on them on many places (even amongst different websites). In this case, be sure to use standard MVC way - HTML helper. These you can easily share between websites, for example you can make your own class library full of them.

Localization in ASP.NET MVC

Visual Studio 2008
I want to bring some localisation into my ASP.NET MVC site.
Someone suggested creating a resource file "Strings.resx" as a publically strongly typed resource, which works nicely and allows me to write
<title><%= Strings.MyView_Title %></title>
I then proceeded to add a file "Strings.da.resx". This file is created right next to the first one, and defaults to "Access Modifier : No Compilation", whereas the first (the one without language modifier) defaulted to "Interal".
I can see in the bin directory that a directory has been created ("da") with a resource.dll, however, I cannot see any of the translated texts on my site.
I have checked with the browser that the only preferred langauge is Danish (da-DK), but I only see the english texts.
Questions:
1) Do I need to enable something in web.config ?
2) Am i creating the right files, with the correct types (i.e. should #2 be "No compilation") ?
In your views, do you have a page directive?
If so, do you have UICulture="Auto" and Culture="Auto"?
For example...
<%# Page Language="C#" Inherits="..."
culture="auto" uiculture="auto" %>
This will ensure that the Accept-Language header, passed by the browser in the request, gets used to set the Thread cultures. It's the UICulture that influences which resource file to pick.
For more on ASP.NET i18n this book is very good...
http://www.amazon.co.uk/NET-Internationalization-Developers-Guide-Building/dp/0321341384/ref=sr_1_1?ie=UTF8&s=books&qid=1241010151&sr=8-1
It doesn't cover MVC, but covers ASP.NET and, as such, many things continue to be relevant.
First you have to create action filter that will switch culture of request thread.
OR
Set your globalization element to UICulture="Auto" and Culture="Auto"
Check this screencast, it is in Russian but code samples are understandable.

Resources