1- i designed application which has two interfaces (english, arabic), the user can choose the UI language at runtime, and the change will be seen after application restarted. i store the selected langauge in app.config.
2- from the form constructor i change the CurrentUICulture to the selected lang by this code:
Public.ArabicView = UmAlQuraCalender.Properties.Settings.Default.ArabicView;
if (Public.ArabicView == true)
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-SA");
else
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
3- the application work without problem in my development machine.
4- when i test the application in another machine, only one user interface is working (english), if i check the other language and restart the application nothing happen the interface remain english although the arabic local is installed.
i use two radio button: one for arabic and the other for english, and inside the click event i change CurrentUICulture to the selected language inside this code:
private void rbArabic_Click(object sender, EventArgs e)
{
Public.ArabicView = rbArabic.Checked;
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-SA");
UmAlQuraCalender.Properties.Settings.Default.ArabicView = Public.ArabicView;
UmAlQuraCalender.Properties.Settings.Default.Save();
MessageBox.Show("UI Language will be changed after application resart");
}
private void rbEnglish_Click(object sender, EventArgs e)
{
Public.ArabicView = rbArabic.Checked;
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
UmAlQuraCalender.Properties.Settings.Default.ArabicView = Public.ArabicView;
UmAlQuraCalender.Properties.Settings.Default.Save();
MessageBox.Show("UI Language will be changed after application resart");
}
5- also how i can debug (trace the source code) in the test machine to figure out the problem?
if any one can help me i will be thankful.
Why can't you use VS to debug on your test machine? Use Remote Debugger tools if test machine doesn't have VS installed.
Another alternative is to use Reflector. Reflector Pro will allow you to step through your code when you don't have source code access.
thanks my friend for your help
i installed VS in the test machine and i discovered that i forget to include the localized DLL which VS Created in the debug directory.
when i included this directory which has the localized DLL for arabic language the problem was solved.
thanks for the every one reply to my question
Related
i'm currently developing a cross-platform App using Xamarin.Forms 3.4 and Visual Studio 2017 (latest version by now).
Since that App should support multiple languages which can be changed on runtime, i'm currently looking into ways to get this done. I already added several resources and translated all interface elements which works just fine. I read through this article to get started:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/
For now, when using the UWP app, the language is automatically set to my current system settings, which is the german language, even if the default app language is english. Thats fine.
Now, I got a method which configures my current language by setting several information, like the default CultureInfo object. That method looks like follows:
public void UpdateAppLanguage()
{
CultureInfo ci;
Language l;
// storage is a class containing several persistent information, like
// the language selected by the user to be used
// the Local attribute states if the language is actually present on
// the current user's system
if(Storage.GetCurrentLanguage().Local == true)
{
// language is present locally, so the user wants to use that one for
// the interface
ci = new CultureInfo(Storage.GetCurrentLanguage().Code);
AppResources.Culture = ci;
CultureInfo.CurrentCulture = ci;
CultureInfo.CurrentUICulture = ci;
CultureInfo.DefaultThreadCurrentCulture = ci;
CultureInfo.DefaultThreadCurrentUICulture = ci;
DependencyService.Get<ILocalize>().SetLocale(ci); // set the Thread for locale-aware methods
}
else
{
// no preferences available yet, use the system's current ci
if (Device.RuntimePlatform != Device.UWP)
ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo();
else
ci = CultureInfo.CurrentCulture;
l = new Language{
Name = ci.EnglishName,
Code = ci.TwoLetterISOLanguageName
};
Storage.SetCurrentLanguage(l);
CultureInfo.CurrentCulture = ci;
CultureInfo.CurrentUICulture = ci;
AppResources.Culture = ci; // set the RESX for resource localization
DependencyService.Get<ILocalize>().SetLocale(ci); // set the Thread for locale-aware methods
}
}
I'm currently testing with a language set, and that language is English.
And here is the dependency service implementation for the UWP sub-project:
public class Localize : stereopoly.ILocalize
{
public void SetLocale (CultureInfo ci)
{
//Windows.Globalization.ApplicationSettings.PrimaryLanguageOverride = ci.Name;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "EN-US";
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
}
public CultureInfo GetCurrentCultureInfo ()
{
return null;
}
}
As you can see, I also tried to set the language to EN-US by force, which doesn't work either. I'm calling the UpdateAppLanguage() method even before the initial Application.InitializeComponent() method runs, I also tried calling it within the OnStart() event method, neither works.
I'd expect the language change getting applied since its executed even before the actual Application starts, but I can switch the several pages of my app as often as I want, the language will always be german, no matter what I do.
I found several answers to this question for plain UWP apps, but not for Xamarin.Forms implementations of UWP projects and that seems to be the problem here, because no other hint regarding pure UWP apps seem to work.
Do you have any idea what might help me?
Thanks.
Make sure you are targeting at least UWP 16299 (FCU), because before that version UWP had issues properly switching languages in debug mode. If you run in Release mode however, it should work normally.
In addition the UWP app needs to know it supports a given language, because this is generated at compile time (using <Resource Language="x-generate"/> in Package.appxmanifest)
You can do this by adding a Strings folder in your UWP project and then adding multiple subfolders - one for each supported language. Finally in each of them add a Resources.resw file (right-click folder, Add > New item..., Resources file (RESW)). The result will look like this.
Then inside each RESW file add some resource. I usually put in AppName, as I often localize it as well:
After this, the app should pick up on the fact that you support the given language and display localized.
I finally found the answer to my problem, it was just as simple as it usually is when it comes to such errors.
It turns out that all bootstrap projects like the UWP, iOS and Android sub-projects also inherit the Assembly Neutral Language from the parent project, no matter what configuration is defined in the specific sub-project (at least thats how it works for UWP). I just noticed that I can set an Assembly Neutral Language within the settings of my .Net main project, and as soon as I did that, all the warnings disappeared and my UWP app ended up showing english text instead of the system default german one. I can also switch back to german now, even though I still have to restart the app to get all frames translated, but thats not that big of a problem, I can work on fixing that up later on. Here's the link that finally got me covered:
Xamarin.Forms: Localization of the UWP app
Thanks for your amazing help anyway :).
I have a pretty old Windows Forms application for which I'm currently trying to build a ClickOnce installer.
Everything is fine except that any attempt to access ApplicationDeployment.CurrentDeployment from within the application results in:
Application identity is not set.
I found a lot of posts of this kind on web and particularly here on Stack Overflow, but people run their application under a debugger or simply not network-deployed local versions.
I emphasize that in my case the application is network-deployed (available offline). I'm running it by clicking the desktop icon created by ClickOnce installer. Update works fine (tried to publish an update to make sure it works).
Nevertheless, ApplicationDeployment.CurrentDeployment is not accessible.
What I'm doing wrong?
In fact, I'm only trying to read the application's version as it appears in the "Programs and Features" applet. Is there a way to read this information without using of ClickOnce API, for example, directly from the registry (I understand that it is not nice).
The code is very simple:
[STAThread]
static void Main(string[] argv)
{
System.Windows.Forms.MessageBox.Show(ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()); // Crash here
DoSomethingUseful();
}
I have done this using a property and bound its value in XAML directly. I am using WPF, but I hope this helps.
private string _verSion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
public string verion
{
get
{
return _verSion;
}
set
{
_verSion = value;
OnPropertyChanged(() => verion);
}
}
I have not done this using a message box. You can try the same. Open a window "About Us" or something. Take a string and bind it to this property.
I am currently building an application in C# which supports French, English and Spanish. I am using resource files (.resx) to store my text following this method I found online. Right now, the resource files I have are the following : TextLabels.resx, TextLabels.en.resx, TextLabels.fr.resx and TextLabels.es.resx.
I use the following method to link my the resource to my form :
manager = new ResourceManager("MyProject.TextLabels", typeof(MyForm).Assembly);
to change the labels when I have selected a new language, I created a refresh method changes the Text attributes of my containers with the method :
Text = manager.GetString("MY_STRING_VARIABLE", culture);
Also, I make sure to change the culture used when the user clicks on the desired using the following method :
culture = CultureInfo.CreateSpecificCulture("es"); //changes the culture to spanish
So here is my problem : I use a 64 bit Windows 7 computer installed in English (I am not sure if it matters) and this method works fine, all my labels are changed in the desired language. The problem occurs when I try use my project on my colleague's computer which is a Windows 7 32 bits computer in French. Using his computer, it looks as if the program (that I have compiled with Visual Studio 2012) can only find the default resource file (TextLabels.resx). So I am at a loss here and wondering 1. Is the 32 bit system or French installation of Windows the reason of my problem or is it something else and how can I make my application work on his machine?
If you are generating localized binaries, be sure that they get deployed with the app.
They would be in the /bin/Debug and /bin/Release folders.
All, I have a localised WinForms application. I have created a facility where users are able to change the required culture/language of the application at runtime. To avoid doing anything fancy, when the use does want to change the culture they are prompted that the application must be restarted for the change in culture to take effect (reasonable as this is not going to happen often if at all). I then store the new language required as a string in one of my settings XML files ("de-DE", "en-US", "en-GB" et al.). Then when the application restarts, if required I switch to the required culture:
// Main constructor.
public SqlEditorForm(string[] args)
{
// Load settings.
username = Environment.UserName;
userSettings = UserSettings.Instance();
advUserSettings = AdvanceUserSettings.Instance();
CheckChangeCurrentCulture();
isInitialising = true;
InitializeComponent();
...
}
private void CheckChangeCurrentCulture()
{
//if (!Debugger.IsAttached)
// Debugger.Launch();
if (advUserSettings.DefaultCulture)
return;
else
{
CultureInfo culture = new CultureInfo(advUserSettings.CustomCultureString);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
}
Now when running in debug/release mode from VS2012, this mechanism works fine. However, when I install the application on (running Windows 7 (x86/x64)) various machines this mechanism no longer works, that is to say that the culture does not switch from the machines default EVER.
I have attached the debugger to the installed application and the code to change the culture is being invoked and the logic seems to be working and no exceptions are thrown, but the culture/language does not change. I have been though many questions on SO but cannot find an applicable one that covers this particular issue.
Why is this mechanism working from VS2012, but not for the installed application? What do I need to do in order to achieve my desired behaviour?
Thanks for your time.
Note, I have also tried replacing the call to CheckChangeCurrentCulture(); with:
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
which also works within VS2012 (Debug and Release modes) but not with the installed application. I have also changed the machines culture Start -> Control Panel -> Region and Language to German ("de-DE") expecting the application and the .NET framework to detect I have that culture available and use it. This also failed for the installed application.
Maybe on your production machines the sattelite assembly of the new culture cannot be loaded for some reason and hence your application falls back to the neutral culture.
Check with Microsoft sysinternals Process Monitor tool for unsuccessfull satellite assembly file accesses.
You an also check with .NET fuslog tool http://msdn.microsoft.com/en-us/library/e74a18c4.aspx
The data connection dialog is a database tool component released with Visual Studio. It allows users to build connection strings and to connect to specific data sources. Its source code has been released on Code Gallery.
It's very useful, but the only problem is that its UI is always in English, regardless of the fact that it's run under a localized version of Windows.
Maybe I missed some tricks?
I tried to use it in a WPF app:
DataConnectionDialog dcd = new DataConnectionDialog();
DataConnectionConfiguration dcs = new DataConnectionConfiguration(null);
dcs.LoadConfiguration(dcd);
dcd.SelectedDataSource = DataSource.SqlDataSource;
dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
...
if (DataConnectionDialog.Show(dcd) == System.Windows.Forms.DialogResult.OK)
{
...
}
Bad news: It's not localized by default
Good news: The project is easy localizable by adding the resources for the language that you need.