use different spellcheck language and change windows default Language - c#

Hi I want to create a small program to change windows default language while spell check the user input in any text area in windows. I know too many programs like MS Word or Word Pad, specially these online text editors have spell check so no need to write it from 0 to 100 right?
My primary language for this project is English but I don't know can I use spell check for other languages like French, Arabic, Turkish etc.
I have this for changing language :
public struct LanguageHelper
{
public static void SetLanguage2English()
{
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("en-US"));
}
public static void SetLanguage2French()
{
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("Fr-FR"));
}
}
I don't any new lead to use it for this project. Thanks in Advance for every hint or new lead that can help me to complete my project.

Related

C# Multi-language Localize resources Windows Forms - how to do not apply empty resource for controls?

I can't use normal localization for Windows Forms for project i am currently working on (it's not support multi-language resx files well due to merge system).
So i wrote workaround for that:
private static readonly ComponentResourceManager resources = new ComponentResourceManager(typeof(Form_GUI));
private void ApplyRes(Control.ControlCollection cc, CultureInfo ci)
{
foreach (Control c in cc)
{
if (excludeControls.Contains(c.Name))
continue;
resources.ApplyResources(c, c.Name, ci);
if (c.Controls.Count > 0)
ApplyRes(c.Controls, ci);
}
}
The problem is for some cases, i am not sure if this connected to deep level of item or something else. I am getting blank values after language change.
So if there a way to check if localize resource contains value for control than change it, if not - let it stay in default (English) language.
Totaling: do not try to apply empty value.
Also want to mention i am using in form custom component, for some reason it do not switch back to english language, once any other language was chosen, but normally switch to other localized languages. Other forms elements work ok.
Is there any way to do so? Will be appreciative for help! :)

Localization on Xamarin.iOS

I'm trying to figure out localization on Xamarin.iOS. I am new to localization in general, but the first language we want to do is Icelandic. If you look on the settings for the iOS device itself Icelandic is not an option. So this is a two part question.
How can I set up localization within my app? Do I just localize in the same manner as other .net apps..or is there something specific to iOS/Xamarin that I need to do.
Once I implement this, how do I get it to choose Icelandic as the language since iOS does not have it as an available language?
Documentation seems to be sparse on this topic.
How can I set up localization within my app?
iOS has its own way to handle localizations. For each language you need to create a folder in your project named language.lproj where language is ISO 639-1 or ISO 639-2 language code. Two character ISO 639-1 codes are preferred (e.g. en, de, fr, it, ...). You can find a table with ISO 639-1 and ISO 639-2 codes here.
In your newly created folder you need to create a file named Localizable.strings and here you can add your strings which you want to localize:
"stringToLocalize" = "This is the translation";
And to assign a localized string for example to a UILabel:
UILabel label = new UILabel();
...
label.Text = NSBundle.MainBundle.LocalizedString("stringToLocalize", null);
You can even create an extension method (credit to anotherlab):
public static class LocalizationExtensions
{
public static string t(this string translate)
{
return NSBundle.MainBundle.LocalizedString(translate, "", "");
}
}
How do I get it to choose Icelandic as the language since iOS does not have it as an available language?
I don't think there is a way to choose Icelandic as a language in iOS. One of our apps uses German, Italian and French localizations. Since we don't need English we created en.lproj folder with German localizations in it. This way even if the language of the device is set to English, German texts will appear. Maybe you can do something like this too in your app.

How to train a user who is using my code which implements system.speech and SpeechRecognitionEngine

I have already coded using the System.Speech.Recognition namespace and use a XML SRGS file for grammer and the SpeechRecognitionEngine.
I want to be able to lead the user through a training of the words or phrases that are important for the app I have written.
I have just seen and read this How to train SAPI I understand that this example uses the unmanaged API (this api exposes a little more) but is exactly the same as far as the engine is concerned.
So if I now set up a form and follow the instruction from the link to initiate training. Can i have my own text on the form and ask the user to read this text. Then conclude the training as indicated in the link. This procedure will train my speech engine that I have already coded with the System.Speech.Recognition namespace.
If I am incorrect is the next best, that I get a user to open their system panel, start the speech recognizer and get them to dictate into maybe Notepad my special phrases until it gets them right most of the time.
Or can i only suggest to them to do the general training?
Conclusion and a few other things
The C/C++ speech developers reference has many more things in it than the Automation reference. When you see here in this forum or others posts from especially Eric Brown and his blog he is more than likely referring to the C/C++ methods.
Using the below code on a Win 7 x64 bit machine for the first time caused me to get a "Class not registered" exception and Google did not help me to solve the problem. I needed to target at least "anycpu".
Otherwise the below is perfect, it basically starts the Training part of the UI that you would otherwise get from the Speech Recognizer interface in Control Panel, except you have your own words. This is perfect.
A simpler alternative is to run the existing training UI with your own training text. The automation-compatible APIs (Microsoft Speech Object Library, aka SpeechLib) expose IspRecognizer::DisplayUI, and you can call that with your own training text.
The training text needs to be a double-null terminated string, also known as a multistring. Here's some code that converts a string array to a multistring:
static string StringArrayToMultiString(
ICollection<string> stringArray
)
{
StringBuilder multiString = new StringBuilder();
if (stringArray != null)
{
foreach (string s in stringArray)
{
multiString.Append(s);
multiString.Append('\0');
}
}
return multiString.ToString();
}
Then, to actually call DisplayUI, you would do something like this:
static void RunTraining(string[] TrainingText)
{
SpSharedRecoContext RC = new SpSharedRecoContext();
string Title = "My App's Additional Training";
ISpeechRecognizer spRecog = RC.Recognizer;
spRecog.DisplayUI(hWnd, Title, SpeechLib.SpeechUserTraining, StringArrayToMultiString(TrainingText);
}

WinRT apps and Regional settings. The correct way to format dates and numbers based on the user's regional settings?

I'm having some problems in Windows 8 Metro apps (XAML & C#) regarding the user's regional settings. It seems that the apps won't respect user's regional settings, so even if your Windows 8 is set to display dates and times in Finnish format, the apps will still display them using US-formatting. But this is such a big problem that there must be something I'm missing?
To test this I started by creating a WPF-application. The application just prints out the CurrentCulture and the formatted DateTime.Now:
private void Culture_Loaded_1(object sender, RoutedEventArgs e)
{
this.Culture.Text = System.Globalization.CultureInfo.CurrentCulture.DisplayName;
}
private void Date_Loaded_1(object sender, RoutedEventArgs e)
{
this.Date.Text = DateTime.Now.ToString();
}
Here's my default regional settings:
When run, the app displayed the date in Finnish format:
Then I changed the regional settings to US:
And when the app was run again, the culture and formatting changed:
This is as I expected everything to work and this is also how I expected WinRT apps to work.
So as a next step, I created a WinRT (XAML & C#) app with the same code and reverted the regional settings back to Finnish. The problem:
Even when I've defined through regional settings that the formatting should be "Finnish", the WinRT app displays the datetime with US-formatting. I then modified the app's project file and made fi-FI the default language:
This change also modified the app's culture:
Strange. I changed the Default Language back to its default value and the formatting was restored to US. I then created folders "Strings - fi-FI" inside the project and added an empty "Resources.resw" to the project. This empty file seems to be enough, as I was now getting the Finnish formatting:
As soon as I remove the empty resource file, the formattings reverts back to US:
Very strange.
This leads to few questions, but the main one I think is: Is it intentional that the WinRT-apps don't follow the user's regional settings like the WPF apps do?
It's been a while, but the question is not fully answered, so let me share my little research. Depechie is mostly right, but he provided only a link and wasn't really sure.
Yes, this unexpected change is intentional. We shouldn't use CultureInfo anymore as it contains legacy codes and Microsoft want us to use Windows.Globalization APIs instead.
To obtain current region we can use:
GeographicRegion userRegion = new GeographicRegion();
string regionCode = userRegion.CodeTwoLetter;
But as I noticed it contains only region information, there's no language code. To obtain language we can use:
string langRegionCode = Windows.Globalization.Language.CurrentInputMethodLanguageTag; // depends on keyboard settings
List<string> langs = Windows.System.UserProfile.GlobalizationPreferences.Languages; // all user languages, like in languages control panel
List<string> applicationlangs = Windows.Globalization.ApplicationLanguages.Languages; // application languages (user languages resolved against languages declared as supported by application)
They return BCP47 language tags in format language-REGION like "en-US" if language has dialects or just language like "pl" if the language doesn't have major dialects.
We can also set one primary language which will override all the rest:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US";
(This is a persisted setting and is supposed to be used at user request)
There is also new API for date, time and numbers:
Windows.Globalization.DateTimeFormatting.DateTimeFormatter dtf = new DateTimeFormatter("longdate", new[] { "en-US" }, "US", CalendarIdentifiers.Gregorian, ClockIdentifiers.TwentyFourHour);
string longDate = dtf.Format(DateTime.Now);
Windows.Globalization.NumberFormatting.DecimalFormatter deciamlFormatter = new DecimalFormatter(new string[] { "PL" }, "PL");
double d1 = (double)deciamlFormatter.ParseDouble("2,5"); // ParseDouble returns double?, not double
There's really a lot more in Windows.Globalization APIs, but I think that this gives us the general idea. For further reading:
date & time formatting sample:
http://code.msdn.microsoft.com/windowsapps/Date-and-time-formatting-2361f348/sourcecode?fileId=52070&pathId=561085805
number formatting & parsing sample:
http://code.msdn.microsoft.com/windowsapps/Number-formatting-and-bb10ba3d/sourcecode?fileId=52249&pathId=1462911094
there's also a nice article titled "How to use patterns to format dates and times" on msdn, but I can add only 2 links
You can also find some topics about the issue on windows 8 dev center forum with some Microsoft employee answers, but they mainly send you to the documentation.
It is intentional. Microsoft is moving away from forcing applications to be in the language of the OS. Instead, each application uses information declared by the application (manifest languages, observable at Windows.Globalization.ApplicationLanguages.ManifestLanguages) and declared by the user (user languages, observable at Windows.System.UserProfile.GlobalizationPreferences.Languages) to determine how to display resources and globalized dates and times. This set of languages is called the application languages (observable at Windows.Globalization.ApplicationLanguages.Languages). The behavior you are seeing is because you are fiddling with the user languages and the manifest languages and you will get different application languages.
Could it be we now need to query other classes? Like the example given here: http://code.msdn.microsoft.com/windowsapps/Globalization-preferences-6654eb36/sourcecode?fileId=52104&pathId=236099476
This post still seems to be relevant even though it was asked two years ago.
I just came across it as I was looking for an answer to about the same thing.
I also wanted to display dates in the regional format in my WP8.1 WinRT app.
The information posted here helps, but it was a bit hard to piece it together.
This is what I came up with and it seems to work for me as the answer I needed:
using Windows.Globalization;
using Windows.Globalization.DateTimeFormatting;
private string FormatDate(int year, int month, int day)
{
GeographicRegion userRegion = new GeographicRegion();
string regionCode = userRegion.CodeTwoLetter;
var formatter = new DateTimeFormatter("year month day", new[] { regionCode });
DateTime dateToFormat = new DateTime(year, month, day);
var formattedDate = formatter.Format(dateToFormat);
return formattedDate;
}

detect un-english formats

i am working with a winform application , and in the richbox_textchange i would like to detect whether the entered text is English or not because if it is english i`ll perform LeftToRight typing else RightToLeft typing .
I used that code :
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (CultureInfo.CurrentCulture.TextInfo.IsRightToLeft)
{
label1.Text = "RTL";
}
else
{
label1.Text = "LTR";
}
}
but i always get : LTR only , label1 never change text to RTL even if i typed arabic !!!
EDIT : ANSWERED !!
Firstly Thanks to everybody for helping me here and especially Oded , here is the solution i could figure out
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (InputLanguage.CurrentInputLanguage.Culture.TextInfo.IsRightToLeft)
{
label1.Text = "RTL";
}
else
{
label1.Text = "LTR";
}
}
You need to add the correct namespace to the top of your class:
using System.Globalization;
At this point the CultureInfo and TextInfo classes will be available directly.
Update:
It appears that you are trying to find out the current input language. Take a look at the InputLanguage class and its methods. It is in the System.Windows.Forms namespace.
InputLanguage.CurrentInputLanguage.Culture.TextInfo.IsRightToLeft
The problem is that CultureInfo.CurrentCulture.TextInfo.IsRightToLeft is returning information about the current system setting, not the specific text that was typed into the textbox.
It has no idea if you've typed English, or Arabic, or Cyrillic into the textbox, and it doesn't care. All it cares about is what your computer is configured to display, that's why it never changes.
Unfortunately, I don't believe it's possible to obtain the language of a particular string of text. You might have some luck with the Text.EncodingInfo.CodePage property, but it's unlikely that anything will tell you the language of text with absolute certainty. Another possible approach is to iterate through the characters in the string, checking them for information. Something like that is described here.
All things considered, it's probably better to just ask the user. What do other applications do that support multiple input languages?

Categories

Resources