n00b question on spacing

Dave Angel davea at davea.name
Sat Jun 22 20:46:02 EDT 2013


On 06/22/2013 08:27 PM, Chris Angelico wrote:
> On Sun, Jun 23, 2013 at 9:56 AM, Dave Angel <davea at davea.name> wrote:
>> On 06/22/2013 07:37 PM, Chris Angelico wrote:
>>>> On the contrary, i18n should be done with config files.  The format
>>>> string
>>
>>
>> **as specified in the physical program**
>>
>>
>>>> is the key to the actual string which is located in the file/dict.
>>>> Otherwise you're shipping separate source files for each language --
>>>> blecch.
>>
>>
>> What I was trying to say is that the programmereze format string in the code
>> is replaced at runtime by the French format string in the config file.
>>
>> But the language is missing the indirection I described.  So you have to use
>> a (function or whatever) wrapper to look up the actual format string in the
>> config file.  My point is by making that file equivalent to a dict, you get
>> to have an executable program in "programmereze" before creating any config
>> files, but still able to handle any real language with one config file per
>> language.
>>
>> This is much preferable to the usual numeric lookup, where somebody
>> specifies the 17th format string to be used at this place in the code. Even
>> when you use C++ names, they're still only a crude approximation to the real
>> purpose of the string.
>
> What you're saying is that there are ways to ameliorate the problem
> with i18n. What that means is that you broadly agree with my main
> point, which is that the format string should be kept as close as
> possible to the arguments. When you're NOT translating to multiple
> languages, the string-literal is the most appropriate way to lay this
> out, imo.
>

Absolutely (very broadly).  And when I am, it's still a string literal, 
just not the one the customer will see.  It still should be next to the 
arguments of the format. I'd be replacing something like:

line = "Customer's name: {%0}, address {%1}".format(args)

with

line = i18n(current_language, "Cussom's name: {%0}, addr {%1}", thename, 
theaddr)

And the English config file would look like (not counting any escaping 
or whatevers):

#SIG - American English, headerline
Cussom's name: {%0}, addr {%1}
    Customer's name: {%0}, addr {%1}

The key has the misspelling's and approximations, while the value has 
the actual string to be used as the object of format.
-- 
DaveA



More information about the Python-list mailing list