problem in letter's language - c#

I have a problem
after i setup windows 7 all old projects in c# vs 2005, the letters that written in arabic changed to a strange language
and i changed the language's settings in control panel to arabic then the new projects passed but the old projects have the same problem

Try this small program and your problem will be solved http://www.zshare.net/download/73795804952ece65/

Windows 7 uses unicode strings whereas your previous projects were using ASCII strings. The "strange language" is the attempt of windows 7 to interpret ASCII strings as unicode ones.
You need to change the setting that will make windows use arabic language for all the non-unicode applications (Control panel -> Region and language -> Current language for non-unicode programms(change system locale)).

Related

How to find OS code page number in .NET Core?

I'm need to get Windows default code page in a .NET Core app. I.e. 1252 on English systems, 1251 on Cyrillic systems, 1253 on Greek, etc. Previously in .NET Framework 4 and Mono it was easily do via Encoding.Default. After the program moved to .NET Core 3.1, now it's need to set code page number manually on each PC by hand. This is not easy for some users.
How to return auto detection of legacy (system) code page? There is no way to read Windows Registry to detect system settings, because the app should also run on Linux with external data received from Windows PCs (or send to that).
Other software which using ANSI code pages for data input and output cannot be rewritten.
Probably OEM code page is interesting too (for seamless interaction with console software, which still using even DOS code page).
The first is a .NET Framework code, the second is its .NET Core equivalent:
//OutputEncoding = Encoding.Default;
OutputEncoding = CodePagesEncodingProvider.Instance.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage);
Long, but working correctly on both Windows and Linux.
DOS, EBCDIC and MacOS encodings can be get similarly via CurrentCulture.TextInfo.*CodePage.
I do not agree with Alexander Tauenis's answer.
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage will still return the old ANSI code page number even if the user enabled the option "Beta: Use Unicode UTF-8 for worldwide language support". In this case, the behaviors of Encoding.Default and CodePagesEncodingProvider.Instance.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage) are different.
Finding the correct code page number in .NET is not easy. Here is a correct way (but unfortunately it invokes Win32API)
In file NativeMethods.cs:
public partial class NativeMethods {
/// Return Type: UINT->unsigned int
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint="GetACP")]
public static extern uint GetACP() ;
}
and get the code page number:
var codepage = NativeMethods.GetACP()
Update:
Invoke Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) and then Encoding.GetEncoding(0) can get the ANSI code page correctly and UTF-8 machines returns UTF-8 correctly. See https://github.com/CnCNet/xna-cncnet-client/blob/7edcf349017963d1777181d79173f636368ad6c0/ClientCore/PlatformShim/EncodingExt.cs for the usage.

C# - Visual Studio 2013 - Not compiling in Greek Language

I have a solution in C# with Windows Forms. The property of a form is set to:
Font: Microsoft Sans Serif, 8.25pt
Design: Language-Greek, Localizable-True
I had written the text, labels etc in English and translated them to Greek.
When making the compilation the debug exe is giving the previously English texts.
Is there a way to have the "greek" version of it?
I assume this has to do with the encoding and all.
Thanks!
There is no need to have Languare or Localizable set to Greek and True.
This is used in special cases when part of the code will automatically transformed.
At the question asked, you need to write your text in Greek as normal (change the language of your OS).

C# program stops working after the language setting in control panel is changed (say, from English to German)

I have a software developed in C#, which is a pure sentefic application. Howver the German users found this software stopped working from time to time, when it is installed on German computers. The temporary solution is to change the Language setting in the control panel, and it works fine after we change the language setting from German to English. This is just a kind of engineering sofware, and the software have nothing relalted to the German or English language. Also, as suggested from other posts in msdn, I have checked the "InitializeComponent()" in the source does several times. There are not strange codes in the "InitializeComponent()" function.
When you change locale, you change the meaning of ',' (comma) and '.' (full-stop) when used in numbers. Could it be that you are trying to parse text containing these characters into numbers?
Does your program attempt to initialize numeric fields with formatted numbers, perhaps?
You need to make sure that your code is sensitive to the user's culture when parsing and formatting text. You also need to make sure you use a consistent culture (e.g. the InvariantCulture) when reading data stored to file or sent over a network.
If you are using .NET Framework 4.5, you might be interested to read about the CultureInfo.DefaultThreadCurrentCulture Property.
In the .NET Framework 4 and previous versions, by default, the culture
of all threads is set to the Windows system culture. For applications
whose current culture differs from the default system culture, this
behavior is often undesirable.
The examples and their explanations on the page could be quite helpful for your issue.
Also, as a side note, try{...}catch{...} blocks are always welcome.

How to get current language for non-unicode programs in .NET? [duplicate]

Anyone have any idea how to get the value of "Language for Non-Unicode Programs" in Control Panel Regional Settings programmatically using c#?
Already tried CultureInfo, RegionInfo and getting the default encoding using the Encoding object, but I can only get the Standards and Formats value or the main code page.
GetSystemDefaultLocaleName or GetSystemDefaultLCID (and its P/Invoke declaration)
The NLS Terminology page in Internationalization for Windows Applications has the answer:
An ANSI application should check the language for non-Unicode programs setting during installation. It uses GetACP or GetOEMCP to retrieve the value. No function is supported to set the language for non-Unicode programs.
The GetACP function returns the "ANSI code page" (e.g. 1252 for english), while GetOEMCP returns the "OEM code page" (the code page used in the console, 437 for english).
Code Pages has more information about code pages in Windows.
IIRC, Thread.CurrentUICulture gets that value.

why the language is change to English in language bar in c#

When I run any project in Visual Studio 2010 the language gets automatically changed to English in language bar of win 7. And when I use the code
Message Box.Show(Thread.Current Thread.Current Culture.Name);
in button event handler. If i select English language or Arabic or any think in the language bar Message Box.Show is print only English
any one help me please
You need to create Resource file for each language, e.g., one for English, another one for Arabic and so on.
You can get more information about .NET Localization from below links:
.NET Localization, Part 1: Resource Managers
.NET Localization, Part 2: Creating Satellite Assemblies
.NET Localization, Part 3: Localizing Text
.NET Localization, Part 4: Localizing Units

Categories