I'm trying to determine whether or not the user would prefer metric or imperial units in my app.
Is there anyway to do this? I've been trying with CultureInfo to no avail.
Cheers,
Cameron.
You want RegionInfo.IsMetric
Related
I am using icCube 5.0 Reporting
I want to assign the value of an Event to that returned by the icCube MDX function UserName()--sort of like #{eventname} = UserName().
Eventually, #{eventname:reportParm} will be sent to a launched report for use in a filter.
Does anyone have any hints for me?
There is no clean way (already in todo list)
For the time being there is no clean way. You've to create a Constant - not an event - in Configuration/Constants that you call for example
ic3c-userName
Assign a javascript expression
:ic3reporting.context_.userInfo().name()
So you've now an event with the name of the user as value you can use.
From version 5.0.3 you can use the new syntax.
For user name:
:ic3reporting.userName()
also you can access the report's name by
:ic3reporting.reportName()
Newbie here. Actually, first question ever.
I've been using NodaTime (on ASP.Net MVC 3 C#) to get around different time zones and am really happy with the results.
But...
I was wondering if there's a way to get the user's culture info based on the time zone - ie: to display the date/time.
Thanks in advance for any help!
UPDATE
Let me be more clear on this...
I'm able to determine the user time zone using jsTimeZoneDetect and NodaTime. It's working perfectly.
Now, what I need is to find out the user locale info (date/time format, etc) to be able to display these info correctly. ie: An user based on US would see the date as 3/21/2013.
I've tried to obtain the locale from the Request.UserLanguages with no avail. IE returns my locale correctly (en-GB), but both Firefox and Chrome are always returning en-US.
I've also changed the web.config and added the following element:
<globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true" />
And that's the piece of code I've been working on:
var userLanguages = Request.UserLanguages;
CultureInfo ci;
if (userLanguages.Length > 0)
{
try
{
ci = new CultureInfo(userLanguages[0]);
}
catch (CultureNotFoundException)
{
ci = CultureInfo.InvariantCulture;
}
}
else
{
ci = CultureInfo.InvariantCulture;
}
string cultureName = ci.Name /* Always returns en-US */
Just as another point, to ask the user to select their locale info is not an option for me. ie: DropdownList on the site, etc.
Any further help? Thanks in advance.
UPDATE 2
Following #JonSkeet advice, I've changed the question title and labels to fit my issue better.
UPDATE 3
Just found out something. The way the language (locale) is returned, depends on the browser, as follows:
Internet Explorer returns the language set on the OS settings, or the browser ones.
Firefox, Chrome, Safari and Opera return the language set on the browser settings.
Considering this, I can't even think about using this information as it comes, because there's no way to guarantee that every single user will change their browser settings. The only info I could rely on is the one coming from the OS settings.
I don't have a clue on what to do now.
To answer the question as asked, regardless of the clarification requested...
In 1.0, we don't have any geographical information available. In 1.1, we're exposing the info from zoneinfo.tab which associates a location with each time zone (or at least most of them) including the country. It doesn't go as far as full culture information (it doesn't differentiate between French Canadian and English Canadian for example, or the various languages spoken in Switzerland) but it gives you some idea. You'd access the information via TzdbDateTimeZoneSource.GeoLocations. (It's only available for TZDB.)
Of course, 1.1 isn't released yet - but we're hoping to do so in the next couple of weeks, almost certainly without any large API changes.
I'd still recommend detecting the culture via the HTTP request normally though.
Please can someone please show me real world example of when it would be advisable to override _setResourceModel to provide different name for collection.
I find it fascinating that magento have given the option of using a custom word for "_collection" but that there is absolutely no evidence of it ever being done.
You might want to have a different name for _collection if you are using multiple datastores
(for example: if you are using MySql and MongoDB).
Pesach
How do I find the country code of the phone?
Or perhaps other information about the country that the phone is at?
You can use the CultureInfo.CurrentCulture.Name property:
String currentCultureName = System.Globalization.CultureInfo.CurrentCulture.Name;
will return the culture name that the phone is set to in the format "languagecode-country/regioncode", for example "en-US"
If you're looking for the country of the devices present location you can pull this from the location service and reverse geocoding. An sample implementation here by Nick Harris.
How to Reverse Geocode a Location to an Address on Windows Phone 7
That is what exactly the globalization part in .net is all about. It stores the culture information in a cultureinfo class. currentculture gives the current culture settings.
The most important class in the System.Globalization namespace is the class CultureInfo. CultureInfo represents a culture and defines calendars, formatting of numbers and dates, and sorting strings that are used with the culture. The class RegionInfo represents regional settings(such as the currency) and shows if the region is using the metric system. In the same region, you can use multiple languages. One example is the region of Spain with its Basque(eu-ES), Catalan(ca-ES), Spanish(es-ES), Galician(gl-ES)cultures
eg: CultureInfo ci = new CultureInfo(“fr-FR”);
Refer More in the PPT
I'd like to ask re: measurement conversion on the fly, here's the detail :
Requirement: To display unit measurement with consider setting.
Concerns:
- Only basic (neutral) unit measurement is going to be stored in database, and it is decided one time.
The grid control has direct binding to our business object therefore it has complexity to do conversion value.
Problem:
How to display different unit measurement (follow a setting), consider that controls are bind to business object?
Your kind assistance will be appreciated. Thank you
ikadewi
If I've understood your question correctly (you are a little vague...) you want to store measurement data in one way, but give the users the option to display it in different ways (using different units). You don't specify which technology/language environment you're using, but there is (at least) one pretty straightforward way to do this: create a converter class.
Here's some pseudo-C# skeleton code if your measurement data is lengths, stored in millimeters. You can probably figure out how to use the same approach for whatever you're measuring, and however you want to display it:
class LenghtConverter {
double ToCentimeters(double millimeters) {
// 1 centimeter = 10 millimeters
return millimeters / 10;
}
double ToInches(double millimeters) {
// 1 inch = 25.4 millimeters
return millimeters / 25.4
}
// You get the drift. Add whatever conversions you need. If you wish,
// you can return strings instead of numbers, and append the unit
// signature as well.
}
Now, in your grid you display your data with some kind of presentation syntax. I'm making something up to give you an idea, and since I'm into ASP.NET the syntax is pretty similar to that. Hope you'll excuse me for that =)
Instead of just
<%= MyMeasurement.Data %>
to display the measurement data in the way it was stored, you output with
<%= LenghtConverter.ToInches(MyMeasurement.Data) %>
which will display the result in inches.
If you're actually using C# (or VB.NET, I suppose) there is a nice feature available in .NET 3.5 called Extension Methods that you might want to use instead. That would let you output with the somewhat cooler and more streamlined syntax
<%= MyMeasurement.Data.ToInches() %>
I have a QML Qt C++ UI. It interfaces with a back-end application.
UI supports both Imperial & Metric modes. User can make this selection from UI at runtime.
User can view and edit data values via the UI.
Back-end application works only in Imperial mode.
A C++ utility object is exposed to QML as a context property. This utility object has methods to:
Set and Get the System of measurement.
Convert unit string from Imperial to Metric. Example: °F to °C.
Convert data value from Imperial to Metric and Metric to Imperial. Example: Fahrenheit to Celsius -> 50 to 10, Celsius to Fahrenheit -> 0 to 32.
C++ data object has these 2 properties:
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QString unitString READ unitString NOTIFY unitStringChanged)
// value - In Imperial mode, you get Imperial value. In Metric mode, you get Metric value.
// unitString - In Imperial mode, you get Imperial units. In Metric mode, you get Metric units.
QVariant data::value()
{
// fetch Imperial data value from back-end application
// get current System of measurement
// if current System of measurement is Metric, convert data value from Imperial to Metric
// return data value
}
QString data::unitString()
{
// fetch Imperial unit from back-end application
// get current System of measurement
// if current System of measurement is Metric, convert unit from Imperial to Metric
// return unit
}
void data::setValue(QVariant value)
{
// get current System of measurement
// if current System of measurement is Metric, convert value from Metric to Imperial
// write value to back-end Controller application
}