Hello, bonjour, and こんにちは to our friends around the world! (Hopefully I got those right
)
Using the new Locale-free string.* templates, we can now build some multi-language support into our own themes!
Since that’s extra work that most people probably won’t go out of their way to do, I’m providing a few pre-built strings for y’all to use! (Definitely not just because I like playing with the new toys. No, no, not at all…
)
This first one is kept simple. It just adds in unit labels between the time components. For us English speakers, that means that the duration:
01:23:45
Will display as:
1 hour 23 minutes 45 seconds
But if someone loaded your theme on a phone set to Spanish, it’ll instead show as:
1 hora 23 minutos 45 segundos
Neat, right? If you want to use that format, just copy the line below and paste it into the Subtitle’s “Custom Text” field in your Album/Artist page.
{%duration.d.nz% }{%string.time.unit.day.other|duration.d>"1"%}{%string.time.unit.day.one|duration.d=="1"%}{ %|duration.d!="0" && (duration.h!="0" || duration.m!="0" || duration.s!="0")%}{%duration.h.nz% }{%string.time.unit.hour.other|duration.h>"1"%}{%string.time.unit.hour.one|duration.h=="1"%}{ %|duration.h!="0" && (duration.m!="0" || duration.s!="0")%}{%duration.m.nz% }{%string.time.unit.minute.other|duration.m>"1"%}{%string.time.unit.minute.one|duration.m=="1"%}{ %|duration.m!="0" && duration.s!="0"%}{%duration.s.nz% }{%string.time.unit.second.other|duration.s>"1"%}{%string.time.unit.second.one|duration.s=="1"%}
“But Cel, that’s kinda long… Can’t we make it any shorter?”
Well, thanks for asking! And yes, of course we can! With just a few tweaks, we can use the short units. Now the duration will display as:
1h 23mins 45secs
Or in Spanish: 1h 23mins 45segs. Notice the “g” as in “segundo”, not a “c” as in “second”.
And here’s that version:
{%duration.d.nz%}{%string.time.unit.day.short|duration.d!="0"%}{ %|duration.d!="0" && (duration.h!="0" || duration.m!="0" || duration.s!="0")%}{%duration.h.nz%}{%string.time.unit.hour.short|duration.h!="0"%}{ %|duration.h!="0" && (duration.m!="0" || duration.s!="0")%}{%duration.m.nz%}{%string.time.unit.minute.short|duration.m!="0"%}{ %|duration.m!="0" && duration.s!="0"%}{%duration.s.nz%}{%string.time.unit.second.short|duration.s!="0"%}
Now that you’ve got a taste for what we can do, let’s move on to the main event…
The final version I am sharing here is what I have built for my own themes. The main difference is that this version does not display the exact durations. Instead, it aims to show only significant time components. Here are a bunch of examples to illustrate:
Examples
As a reminder, all of these units will change to match the user’s preferred language.
Duration: 08:04
Displays as: 8 mins 4 secs
Duration: 23:04
Displays as: ~23 mins
Duration: 23:45
Displays as: 23 mins 45 secs
Duration: 34:45
Displays as: ~34 mins
Duration: 01:02:34
Displays as: ~1 hour
Duration: 01:23:45
Displays as: ~1 hour 23 mins
Duration: 01:02:34:56
Displays as: ~1 day 2 hours
In summary: it will only show at most two time units at once, but will drop the smaller unit if less than my thresholds (at least 10s or 5m is considered “useful info” for the respective unit.) A tilde ( ~ ) appears in front whenever a unit is hidden.
Important: This does not do any rounding! The duration 32:59 will display as ~32 mins not ~33 mins
I may bug Tolriq for rounded durations later, but for now I’m happy we can do this much.
Here is the “copy/paste ready” version:
{~%|duration!=empty && (duration.d!="0" || duration.h!="0" || (duration.h=="0" && (duration.m>"29" || (duration.m>"9" && duration.s<"10"))))%}{%duration.d.nz% }{%string.time.unit.day.one|duration.d=="1"%}{%string.time.unit.day.other|duration.d>"1"%}{ %|duration.d!="0" && duration.h!="0"%}{%duration.h.nz% }{%string.time.unit.hour.one|duration.h=="1"%}{%string.time.unit.hour.other|duration.h>"1"%}{ %|duration.d=="0" && duration.h!="0" && duration.m>"4"%}{%duration.m.nz|duration.d=="0" && (duration.h=="0" || (duration.h!="0" && duration.m>"4"))% }{%string.time.unit.minute.one|duration.d=="0" && duration.h=="0" && duration.m=="1"%}{%string.time.unit.minute.short|duration.d=="0" && ((duration.h=="0" && duration.m>"1") || (duration.h!="0" && duration.m>"4"))%}{ %|duration.d=="0" && duration.h=="0" && duration.m!="0" && (duration.m<"10" || (duration.m<"30" && duration.s>"9"))%}{%duration.s.nz|(duration.d=="0" && duration.h=="0") && (duration.m<"10" || (duration.m<"30" && duration.s>"9"))% }{%string.time.unit.second.one|duration.d=="0" && duration.h=="0" && duration.m<"10" && duration.s=="1"%}{%string.time.unit.second.short|(duration.d=="0" && duration.h=="0" && duration.s>"1") && (duration.m<"10" || (duration.m<"30" && duration.s>"9"))%}
As well as an exploded view, for easier editing. The “Comments” are safe to leave in, but please remember to flatten it to a single line before using it in the app!
Exploded View
{# Display tilde to indicate approximate time when any unit is hidden%|!=%}
{ %|!=%}
{~%|duration!=empty && (duration.d!="0" || duration.h!="0" || (duration.h=="0" && (duration.m>"29" || (duration.m>"9" && duration.s<"10"))))%}
{--------------------%|!=%}
{# DAYS - Always display if non-zero%|!=%}
{%duration.d.nz% }
{ %|!=%}
{## Units are (full) singular/plural as appropriate%|!=%}
{%string.time.unit.day.one|duration.d=="1"%}
{%string.time.unit.day.other|duration.d>"1"%}
{--------------------%|!=%}
{# SEPARATOR between days/hours%|!=%}
{ %|duration.d!="0" && duration.h!="0"%}
{--------------------%|!=%}
{# HOURS - Always display if non-zero%|!=%}
{%duration.h.nz% }
{ %|!=%}
{## Units are (full) singular/plural as appropriate%|!=%}
{%string.time.unit.hour.one|duration.h=="1"%}
{%string.time.unit.hour.other|duration.h>"1"%}
{--------------------%|!=%}
{# SEPARATOR between hours/minutes%|!=%}
{ %|duration.d=="0" && duration.h!="0" && duration.m>"4"%}
{--------------------%|!=%}
{# MINUTES - Display ONLY IF: %|!=%}
{## 1A: Total duration is less than one day%|!=%}
{## -AND- %|!=%}
{## 1B: There are more than "4" minutes%|!=%}
{# -OR- %|!=%}
{## 2: Total duration is less than one hour%|!=%}
{ %|!=%}
{%duration.m.nz|duration.d=="0" && (duration.h=="0" || (duration.h!="0" && duration.m>"4"))% }
{ %|!=%}
{## Units are (full) singular or (short) plural as appropriate%|!=%}
{%string.time.unit.minute.one|duration.d=="0" && duration.h=="0" && duration.m=="1"%}
{%string.time.unit.minute.short|duration.d=="0" && ((duration.h=="0" && duration.m>"1") || (duration.h!="0" && duration.m>"4"))%}
{--------------------%|!=%}
{# SEPARATOR between minutes/seconds%|!=%}
{ %|duration.d=="0" && duration.h=="0" && duration.m!="0" && (duration.m<"10" || (duration.m<"30" && duration.s>"9"))%}
{--------------------%|!=%}
{# SECONDS - Display ONLY IF: %|!=%}
{## 1A: Total duration is less than 30 minutes%|!=%}
{## -AND- %|!=%}
{## 1B: There are more than "9" seconds%|!=%}
{# -OR- %|!=%}
{## 2: Total duration is less than 10 minutes%|!=%}
{ %|!=%}
{%duration.s.nz|(duration.d=="0" && duration.h=="0") && (duration.m<"10" || (duration.m<"30" && duration.s>"9"))% }
{ %|!=%}
{## Units are (full) singular or (short) plural as appropriate%|!=%}
{%string.time.unit.second.one|duration.d=="0" && duration.h=="0" && duration.m<"10" && duration.s=="1"%}
{%string.time.unit.second.short|(duration.d=="0" && duration.h=="0" && duration.s>"1") && (duration.m<"10" || (duration.m<"30" && duration.s>"9"))%}
Thanks for reading! Have fun making your themes!