[Solved] Formatting File Dates in Translations
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
[Solved] Formatting File Dates in Translations
I am currently preparing Japanese and Chinese translations for a Ren'Py game that did not originally contain translations. One of the components is the formatting of the time and date for save files in the FileTime() function, which currently uses "%b %d %Y, %H:%M". For Japanese, Simplified Chinese, and Traditional Chinese, I translated the string in FileTime() to "%Y年%m月%d日 %H:%M". According to several sources, Chinese dates are not to include leading zeroes in the month and day. How can strings be formatted in translation files to strip leading zeroes from %m and %d?
Last edited by AXYPB on Mon Jul 03, 2017 4:45 am, edited 2 times in total.
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Formatting File Dates in Translations
The %b etc parts are python datetime format codes. Have a look at the following link for info on them all
Time Formatting
Hope those give you all the info you need.
Time Formatting
Hope those give you all the info you need.
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Formatting File Dates in Translations
I examined the format codes first, but no codes are provided that return non-zero-padded numbers. I must strip each component number of leading zeroes individually, but in a way that does not complicate the translation process. I've considered doing so in the file screen itself, using a series of concatenated FileTime().lstrip("0") calls, but because each language orders dates differently, this will result in complex code that I wish to avoid.
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Formatting File Dates in Translations
Ah I see. Never really noticed that python didn't support non leading zero days in dates.
I think you likely have 2 options...
Either do as you theorized and strip out zeros from certain parts of the string for certain locales or just go with "%c" or "%x - %X" and hope that suffices.
I think you likely have 2 options...
Either do as you theorized and strip out zeros from certain parts of the string for certain locales or just go with "%c" or "%x - %X" and hope that suffices.
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Formatting File Dates in Translations
As this is a pure python question, there are usually better answers available elsewhere. https://stackoverflow.com/questions/952 ... ro-padding
You'd probably have to fiddle with the FileTime() a little to apply this (I frankly haven't looked), but since it's based on python's inner workings, I consider it a python question. Which is not to criticize OP for asking here! Just trying to be helpful, for future reference.
You'd probably have to fiddle with the FileTime() a little to apply this (I frankly haven't looked), but since it's based on python's inner workings, I consider it a python question. Which is not to criticize OP for asking here! Just trying to be helpful, for future reference.
Re: Formatting File Dates in Translations
I've discovered a solution that involves dividing each component of the timestamp into individual strings, translating them, and using string interpolation to create timestamps appropriate for each locale. lstrip("0") is used on the month and day elements.
This code is used in screens.rpy to create multiple buttons in a file screen.
In the translation files, the strings are reordered to form locale-appropriate timestamps. Each format argument above is translated to add date characters in Asian languages:
This code is used in screens.rpy to create multiple buttons in a file screen.
Code: Select all
for i in range(1,8):
hotspot (20,70 * i,370,60) action FileAction(i):
$ file_name = FileSlotName(i,14)
# Check if the slot queried by FileTime() returns a non-empty string.
# Create a save file hotspot if it does, otherwise only print the slot name.
if FileTime(i) is not "":
add FileScreenshot(i) xpos 5 ypos 5
# Each component of the timestamp is assigned to individual variables,
# allowing them to be reordered and have leading zeroes stripped.
python:
file_year = FileTime(i, format=_("%Y"))
file_month = FileTime(i, format=_("%m")).lstrip("0")
file_eng_month = FileTime(i, format="%b")
file_day = FileTime(i, format=_("%d")).lstrip("0")
# The hour and minute component is formatted with a leading comma and space, which allows
# for localizations in regions that do not use commas to separate date and time.
file_time = FileTime(i, format=_(", %H:%M"))
save_name = FileSaveName(i)
text _("[file_name]. [file_eng_month] [file_day] [file_year][file_time]\n[save_name!t]") style "save_title"
key "save_delete" action FileDelete(i)
else:
text "[file_name]." style "save_title"
Code: Select all
translate japanese strings:
old "[file_name]. [file_eng_month] [file_day] [file_year][file_time]\n[save_name!t]"
new "[file_name]. [file_year][file_month][file_day] [file_time]\n[save_name!t]"
old ", %H:%M"
new "%H:%M"
old "%Y"
new "%Y年"
old "%m"
new "%m月"
old "%d"
new "%d日"
Who is online
Users browsing this forum: 3N16M4