Opened 9 years ago

Closed 23 months ago

#2571 closed defect (fixed)

wxLocale::GetSystemEncodingName() returns empty string under OS X

Reported by: pitrou Owned by: csomor
Priority: low Milestone:
Component: wxOSX (any toolkit) Version: stable-latest
Keywords: simple Cc: pitrou, csomor
Blocked By: Blocking:
Patch: no

Description

On MacOS X, wx.Locale.GetSystemEncodingName() returns
the empty string whereas wx.Locale.GetSystemEncoding()
returns the proper value.

This is a problem when you need to use the standard
Python methods unicode.encode() and str.encode(). They
expect the literal name of the encoding (e.g.
('utf-8')), not a wx-custom numeric values.

GetSystemEncodingName() does return the proper value
under Linux and Windows.

Attachments (1)

2571.patch download (1.0 KB) - added by oneeyeman 23 months ago.
Ticket implementation

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 years ago by wxsite

  • Status changed from assigned to confirmed

transitioning old 'assigned' status to new 'confirmed' status

comment:2 Changed 2 years ago by oneeyeman

Calling this function on Mac OSX Snow Leopard on Cocoa minimal gives the string "Message".

However the documentation says that it shouldn't be used by the client code.

comment:3 Changed 2 years ago by vadz

  • Component changed from wxOSX-Carbon to wxOSX (any toolkit)
  • Keywords simple added
  • Priority changed from normal to low
  • Summary changed from wx.Locale.GetSystemEncodingName() empty to wxLocale::GetSystemEncodingName() returns empty string under OS X
  • Version set to 2.9-svn

I have no idea where does "Message" come from but the comment in this function does say that it intentionally returns an empty string under OS X. I don't see why would this be useful behaviour though. It seems we should return

CFStringGetNameOfEncoding(CFStringGetSystemEncoding())

from there, shouldn't we?

comment:4 Changed 2 years ago by oneeyeman

Vadim,

I think you are wrong.

I don't know much but it seems that according to https://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html

an application needs to call GetApplicationTextEncoding().

comment:5 Changed 2 years ago by vadz

I don't believe we need to use GetApplicationTextEncoding() here but wx API is insufficient here anyhow, we need to have more precise functions. For now returning the encoding corresponding to the user's preferred language seem to be consistent with GetACP() under Windows (which is itself probably wrong however...).

comment:6 Changed 23 months ago by oneeyeman

I tried to make a patch for Vadim's suggestion, but failed.

I will leave it for someone who is more familiar with wxCocoa internals.

Changed 23 months ago by oneeyeman

Ticket implementation

comment:7 Changed 23 months ago by oneeyeman

Attached please find the implementation suggested by Vadim.

Tested on Cocoa build against 10.6 SDK.

On my Mac it returns "Western (Mac OS Roman)".

comment:8 Changed 23 months ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [72985]) Implement wxLocale::GetSystemEncodingName() for wxOSX.

Use CFStringGetNameOfEncoding() to get the canonical name of the encoding from
OS X itself.

Closes #2571.

Note: See TracTickets for help on using tickets.