I am using kendo UI to create an input box,
I want to automatically display the amount user have to pay in the textbox before,
so that user will only have to insert an amount if it differs from default
The data is given as decimal number.
I have tried:
#(Html.Kendo().CurrencyTextBoxFor(model => model.Paid).Format("R#0.00").Min(0))
And now also:
#(Html.Kendo().NumericTextBoxFor<decimal>(model => model.Paid).Format("R#.##").Min(0))
for some reason the textbox just keeps displaying two extra zeros
For some reason the textbox just keeps displaying two extra zeros
Yes, as per my investigation upon your code snippet it might be because of your default-culture. However, we can customize it as per the requirement. You could follow below steps:
Program.cs:
var defaultCulture = "en-US";
var ci = new CultureInfo(defaultCulture);
ci.NumberFormat.NumberDecimalSeparator = "."; // Defining my preferrence for number
ci.NumberFormat.CurrencyDecimalSeparator = ".";
// Configuring Number Seperator Using Localization middleware
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(ci),
SupportedCultures = new List<CultureInfo>
{
ci,
},
SupportedUICultures = new List<CultureInfo>
{
ci,
}
});
Note: As you can see in NumberFormat.NumberDecimalSeparator I am setting my preferrence for seperator. You are open to use anything you want, any kind of charaters. Please consider the order as well while placing the code in middleware. Best use would be end of your current middleware. As following:
Update for Classic Asp.net 4.8 and Older:
We can configure above steps for asp.net classic project as well. To set the UI culture and culture for all pages, add a globalization section to the Web.config file, and then set the uiculture and culture attributes, as shown in the following example:
<system.web>
<globalization
culture="en-US"/>
</system.web>
Note: More details can be found here in official document.
Output:
Note: For further reference you could check our official document below.
Custom numeric format strings
The "." custom specifier
Related
I want to serve pages with culture info in the URL.
For example, About.cshtml should serve these URLs:
/about
/en/about
/ru/about
I can achieve that using app.UseRewrite(). Here's my code:
var options = new RewriteOptions()
.AddRewrite(#$"/(en|ru|ar)/?(.*$)", "/$2", skipRemainingRules: true);
app.UseRewriter(options);
However, I also need to extract the currently selected culture and put it inside HttpContext.Items.
How can I do that while rewriting the URL?
On my browser that I run from my local environemnt, the strings are translated as supposed to. When I upload to Azure, it still works. However, when I switch to Edge (that I never use for anything other than downloading FireFox), the strings are not translated anymore. I verified with external users on a wide range of browsers and it seems be platform independent issue.
I have all my translations in a global file placed in the root directory and I have the dummy file so I can inject it into views and controllers, as proposed by the docs. Somehow, the RESX file seems not to be found so I put it to Always upload. No change in misbehavior, though.
I'm not sure how to diagnose it further or if the RESX file is compiled into the DLL or uploaded straight off to the server and read from on the fly. Is it possible to verify that the file is "up there" somehow?
My config is like this.
public void ConfigureServices(IServiceCollection services)
{
...
services.AddLocalization(a => a.ResourcesPath = "");
services.Configure<RequestLocalizationOptions>(a =>
{
CultureInfo[] supportedCultures = {
new CultureInfo("sv-SE"),
new CultureInfo("se")
};
a.DefaultRequestCulture = new RequestCulture("se");
a.SupportedCultures = supportedCultures;
a.SupportedUICultures = supportedCultures;
});
...
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseRequestLocalization();
...
app.UseMvcWithDefaultRoute();
}
edit
I've noticed that it works in Chrome when I have those lines.
RequestLocalizationOptions options = app.ApplicationServices
.GetService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization(options);
It stops working when I have those instead.
//RequestLocalizationOptions options = app.ApplicationServices
// .GetService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization();
In IE it doesn't work in either case.
Couple words about culture configuration. I guess you wanted to specify only Swedish locale so you have these line of code
CultureInfo[] supportedCultures = {
new CultureInfo("sv-SE"),
new CultureInfo("se")
};
It turns out that sv-SE is definitely Swedish culture, but se is Northern Sami culture. If your intention is only Swedish culture you need to set sv instead of se
CultureInfo[] supportedCultures = {
new CultureInfo("sv-SE"),
new CultureInfo("sv")
};
a.DefaultRequestCulture = new RequestCulture("sv");
Back to the main problem. By default there are 3 ways to set request culture, via query string, cookies or Accept-Language header. It looks like you don't specify a culture in request cookies or query string, but your browser sends Accept-Language header from which ASP.NET Core reads request culture. If a browser sends en-US, en, and sv cultures, none of them matches to supportedCultures (which are sv-SE and se) the framework falls back to DefaultRequestCulture (which is se) and reads resources from Lingo.se.resx and everything is fine. But it looks like Edge (on any other browser but on another computer) sent different set of cultures within Accept-Language header which included sv-SE containing in supportedCultures. So resource reader searched for Lingo.sv-se.resx or Lingo.sv.resx file but with no luck and thus no translation were provided.
If my assumption is right changing se to sv in your code and renaming Lingo.se.resx to Lingo.sv.resx will fix the problem.
I'm looking for the best approach for storing strings in kentico and accessing them programmatically similar to how you would access app.config settings.
Scenario:
I wish to create an ITask, which when executed will generate a number of HTML templates. I would allow entry of the text fields via Kentico. The templates are backbone templates.
My initial thought would be to store them in UI Culture and then access them via the task but I'm having some difficulty doing this as it's a scheduled task I don't have access to the HttpContext.
Potentially I should be storing these values in custom settings?
so i found the answer.
// ResHelper
using CMS.GlobalHelper;
using CMS.SiteProvider;
// Get culture ID from query string
var uiCultureID = QueryHelper.GetInteger("UIcultureID", 0);
// Get requested culture
var ui = UICultureInfoProvider.GetSafeUICulture(uiCultureID);
var dui = UICultureInfoProvider.GetUICultureInfo(CultureHelper.DefaultUICulture);
var s = ResHelper.GetString("myculturevalue.test", dui.UICultureCode);
for those interested in the task, take a look here http://devnet.kentico.com/Blogs/Martin-Hejtmanek/June-2010/New-in-5-5-Provide-your-classes-from-App_Code.aspx
thanks
I am developing a site in asp.net in multiple languages but i didn't understand how this can be done because we can manage multilingual language by using resource files. we did this, but my major problem is that how we can change globalization at run time for a particular user. if A user choose English language then he/she can view this i English and if B user choose Spanish then he/she can view this site in Spanish. How we can do this? or how we can choose a particular language resource file???
use this code
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); //'en-US' these values are may be in your session and you can use those
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");//'en-US' these values are may be in your session and you can use those
base.InitializeCulture();
}
I had this same question when i started developing multilingual sites and i found those two articles as the best starting point:
http://www.codeproject.com/KB/aspnet/localization_websites.aspx
http://www.codeproject.com/KB/aspnet/LocalizedSamplePart2.aspx
you could try something like this:
string culture = "en-US"; //could come from anything (session, database, control, etc..)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
I think it works!
you need to use localization for language and individual resource file. Now when your site is being access at client side you need to check the locale setting on client's machine his date/time setting and the Default language ... on the basis of this you can provide language that user wish...
How can I make a website multilingual?
I want to create a website and in the home page i want the client to choose a language from English and Arabic. Then the whole website is converted to that language. What should I do to achieve this? I am creating this website in asp.net 2.0 with C#
What you're asking for is a tutorial, which you really should try googling for. Look at the links below, if there's something particular, more specific you don't understand - ask the question here.
http://www.beansoftware.com/ASP.NET-Tutorials/Globalisation-Multilingual-CultureInfo.aspx
http://www.asp.net/learn/Videos/video-40.aspx
http://www.about2findout.com/blog/2007/02/aspnet-multilingual-site_10.html
Good luck!
ASP.NET can use a number of mechanisms to change language settings - however you will need to perform the translations your self.
You could look at using Resource files for the common elements of your site - see this answer to Currency, Calendar changes to selected language, but not label in ASP.NET
However, for the main content you'd probably want to do something with the URL to ensure that your content is served correctly - the links that Honsa has supplied would be a good place to start.
Sample code i have done using resource file add global.asax
void Application_BeginRequest(Object sender, EventArgs e)
{
// Code that runs on application startup
HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
if (cookie != null && cookie.Value != null)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
}
}
http://satindersinght.blogspot.in/2012/06/create-website-for-multilanguage.html
http://satindersinght.wordpress.com/2012/06/14/create-website-for-multilanguage-support/
For Arabic you need to change the direction left to right