Python程序与日期时间本地化

Python程序与日期时间本地化,python,datetime,localization,Python,Datetime,Localization,我做了一个小Python程序: # -*- coding: utf-8 -*- """ Program that ask for the birth date and return the day name of the birth """ from datetime import datetime def ask_birthdate(): """ Raw input of the birth date """ date = raw_input("Enter your bir

我做了一个小Python程序:

# -*- coding: utf-8 -*-
""" Program that ask for the birth date and return the day name of the birth """

from datetime import datetime

def ask_birthdate():
    """ Raw input of the birth date """
    date = raw_input("Enter your birth date (DD-MM-YYYY) : ").strip()
    return datetime.strptime(date, '%d-%m-%Y')

def birthday(date):
    """ Localized day of birth """
    return date.strftime('%A')

if __name__ == "__main__":
    date = ask_birthdate()
    print u"You was born a %s" % birthday(date)
这很简单,但我想翻译一下。 首先是IHM文本(输入您的出生日期)和(您出生于a),然后我还要翻译日期的名称


在文档中,我看到它应该本地化,但是我应该如何配置要本地化的程序?

我想您正在寻找

只需在代码中添加以下行:

import locale

... 

locale.setlocale(locale.LC_ALL, '<desired local>')
# NOTE: using locale.setlocale(locale.LC_ALL, '') will use the machine's default locale defined in the LANG environment variable.
Enter your birth date (DD-MM-YYYY) : 15-08-2012
You was born a Mittwoch

我想你是在找那个

只需在代码中添加以下行:

import locale

... 

locale.setlocale(locale.LC_ALL, '<desired local>')
# NOTE: using locale.setlocale(locale.LC_ALL, '') will use the machine's default locale defined in the LANG environment variable.
Enter your birth date (DD-MM-YYYY) : 15-08-2012
You was born a Mittwoch

如果要指定“”,则必须从系统区域设置中选择一个:
locale-a
,如果要指定“”,则必须从系统区域设置中选择一个:
locale-a