views:

82

answers:

1

Hi,

My client has given me a custom TTF font only for English. So my intention is to load that TTF only for English and for other languages it should fallback to the available System font.

I am doing the following steps:

  1. Registering fonts with my app. Copying into Resources folder and add to my project.
  2. Loading the font with name.

    NSMutableDictionary * aTitleAttributes = [[[NSMutableDictionary alloc] initWithObjectsAndKeys:
          [NSFont fontWithName:CP_FONT_NAME size:[NSFont systemFontSize]], NSFontAttributeName,
           aParagraphStyle, NSParagraphStyleAttributeName,
                nil] autorelease];
    

But this results into another problem, since I am loading the fonts in this way for all the languges, my localization text looks english. Hence I think I should have some condition like

NSFont *font = nil;
If (currentLocaleIsEnglish()) {
/// font to load my custom TTF
}
Then use [NSFont fontwithName:font ...]

So can anybody help me to realize whatever I am doing is right with registering the font with App. If so how can I register my font only for English version. Because for other locales this font is not available then NSFont::fontWithName will return nil and automatically fallsback to the SystemFont and hence my locale shall be shown properly.

Otherwise I have to have a condition like what I mentioned above, which is a crude way of doing. If so how can I write such an API for finding currentLocale Is English?

Regards Mustafa

+1  A: 

Get the current locale from NSLocale, then send it an objectForKey: message and ask for NSLocaleLanguageCode. If the current language code is en, en_US, en_GB, en_AU, or en_CA, then the current language is some form of English.

To simplify the test, you can put the language codes into an array or set and test the current language code's membership in that collection. Or, better yet, put them into a dictionary as the keys, with the value for all of them being CP_FONT_NAME; then, if the client later provides other fonts for other languages, you can add those new font-language pairs easily.

Peter Hosey