discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnustep] Localization


From: Pascal J. Bourguignon
Subject: Re: [Discuss-gnustep] Localization
Date: Thu, 21 Sep 2000 19:00:06 +0200 (CEST)

> From: Nicola Pero <n.pero@mi.flashnet.it>

> > You then use NSBundles localizedStringForKey:value:table: method to fetch 
> > the
> > appropriate localized version for each string you want to localize.
> 
> I don't know much about this - but - are there any plans for some simpler
> GNUstep extension/front-end to this ?
> 
> In gettext (used by GNOME, KDE, and most of GNU stuff) a programmer simply
> does: 
> 
> char *myString = _("Hello World");
> 
> instead of 
> 
> char *myString = "Hello World";
> 
> that's all you need to make your app localized ("_" is something - macro
> or function - which expands the string to the version in the current
> locale), a part from calling the gettext initialization at the beginning 
> of your app.  I don't remember how this works with not-ASCII charsets.
> 
> Anyway, it is so simple I have never seen a GNOME app which
> is not-localized (perhaps the translation is missing, but the app can 
> use any translation as soon as someone provides it).
> 
> Perhaps shouldn't we add some similar trick to the gnustep libraries ? 
> 
> Actually, if I have to say it all :), and scandalize everyone with a
> modest proposal, why don't we hack NSConstantString to automatically and
> silently translate every constant string into the current locale.

We're not scandilized,  it's simply not possible to  translate all the
strings in a program, because not all the strings are meant to be read
by the user. How would you localize the following string?

    NSSystem(@"echo 'int f(int x){return(x*2);}'>/tmp/a.c;"
             @"cc -o /tmp/a.o -c /tmp/a.c");

And this one?

    const NSString* monthSize=@"1.1010110101";
    const NSString* query=@"SELECT code,name FROM dish WHERE calories<1000;"


> That would be programmer-friendly programming: everything you write is
> always and automatically localized without programmer's intervention.  It
> would even be better than gettext - you don't even need the _(). 

You always can define your own macro:

    #define _(s) NSLocalizedString(s,@"No Comment!")



However, note that the NSBundle macros are more functionnal than that:
they allow to associate a comment to a key, to help the translator.

  NSLocalizedString(@"cheese",@"The generic name for the fermented milk stuff")
  NSLocalizedString(@"cheese",@"What you say to smile in a picture")

Translated in  Spanish, for example,  the first will be  translated as
@"queso", and the second as @"patata".




By the  way, you should probably  duplicate a lot of  string, for each
use of them,  because they may be translated  differently depending on
the context.

  NSLocalizedStringFromTable(@"Commencer téléchargement",\
                              @"Pour envoyer vers le serveur")

would be translated to @"Start uploading", while

   NSLocalizedStringFromTable(@"Commencer téléchargement",\
                              @"Pour recevoir les données")

woule be translated to @"Start downloading".




Then, you can spread your  strings thru several string tables that may
be overlaid in memory (loaded only when and if needed). You'd use:

    NSLocalizedStringFromTable(key, tbl, comment)



Also, a  localizable string  may be linked  to a specific  bundle (for
modularization sake). You'd use:

   NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment)




Of course, you could define:

 #define _(s) NSLocalizedStringFromTableInBundle(s,TABLE,BUNDLE,@"No Comment!")

and then, in each source file, 

#undef  TABLE
#define TABLE @"The table where to store the localizable strings  of this file"
#undef  BUNDLE
#define BUNDLE @"The bundle to which this file belongs"

before using _().



-- 
__Pascal Bourguignon__    PGP Key ID:      0xEF5E9966
mailto:pjb@imaginet.fr    PGP fingerprint: 00 F5 7B DB CA 51 8A AD 04 5B 
http://www.imaginet.fr/~pjb/               6C DE 32 60 16 8E EF 5E 99 66

() Join the ASCII ribbon campaign against html email and Microsoft attachments.
/\ Software patents are endangering the computer industry all around the world.
   Join the LPF:     http://lpf.ai.mit.edu/      http://petition.eurolinux.org/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]