From 596717bf3232f826024df5e7ee600adeb0bc9fb1 Mon Sep 17 00:00:00 2001 From: TheSumm Date: Tue, 20 Jan 2015 16:18:04 +0100 Subject: [PATCH] Added locale number formatting to locale files --- data/locales/de.lua | 4 ++++ data/locales/en.lua | 4 ++++ data/locales/es.lua | 4 ++++ data/locales/pl.lua | 4 ++++ data/locales/pt.lua | 4 ++++ data/locales/sv.lua | 4 ++++ modules/client_locales/locales.lua | 16 ++++++++++------ 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/data/locales/de.lua b/data/locales/de.lua index 5ce0f7f5..9637d661 100644 --- a/data/locales/de.lua +++ b/data/locales/de.lua @@ -4,6 +4,10 @@ locale = { charset = "cp1252", languageName = "Deutsch", + formatNumbers = true, + decimalSeperator = ',', + thousandsSeperator = ' ', + translation = { ["1a) Offensive Name"] = false, ["1b) Invalid Name Format"] = false, diff --git a/data/locales/en.lua b/data/locales/en.lua index 3bcf03a7..55081109 100644 --- a/data/locales/en.lua +++ b/data/locales/en.lua @@ -3,6 +3,10 @@ locale = { charset = "cp1252", languageName = "English", + formatNumbers = true, + decimalSeperator = '.', + thousandsSeperator = ',', + -- translations are not needed because everything is already in english translation = {} } diff --git a/data/locales/es.lua b/data/locales/es.lua index 917a1b4f..0e67deb1 100644 --- a/data/locales/es.lua +++ b/data/locales/es.lua @@ -7,6 +7,10 @@ locale = { charset = "cp1252", languageName = "Español", + formatNumbers = true, + decimalSeperator = ',', + thousandsSeperator = '.', + translation = { ["1a) Offensive Name"] = "1a) Nombre ofensivo", ["1b) Invalid Name Format"] = "1b) Formato invalido para nombre", diff --git a/data/locales/pl.lua b/data/locales/pl.lua index 3a74f0f7..a7c38131 100644 --- a/data/locales/pl.lua +++ b/data/locales/pl.lua @@ -2,6 +2,10 @@ locale = { name = "pl", languageName = "Polski", + formatNumbers = true, + decimalSeperator = '.', + thousandsSeperator = ' ', + translation = { ["1a) Offensive Name"] = "1a) Obrazliwe Imie", ["1b) Invalid Name Format"] = "1b) Niepoprawny Format Imienia", diff --git a/data/locales/pt.lua b/data/locales/pt.lua index 1cc91f03..e5dc3b0b 100644 --- a/data/locales/pt.lua +++ b/data/locales/pt.lua @@ -3,6 +3,10 @@ locale = { charset = "cp1252", languageName = "Português", + formatNumbers = true, + decimalSeperator = ',', + thousandsSeperator = '.', + -- As traduções devem vir sempre em ordem alfabética. translation = { ["%d of experience per hour"] = "%d de experiência por hora", diff --git a/data/locales/sv.lua b/data/locales/sv.lua index c060195a..d6263f49 100644 --- a/data/locales/sv.lua +++ b/data/locales/sv.lua @@ -5,6 +5,10 @@ locale = { charset = "cp1252", languageName = "Svenska", + formatNumbers = true, + decimalSeperator = ',', + thousandsSeperator = ' ', + translation = { ["1a) Offensive Name"] = "1a) Offensivt Namn", ["1b) Invalid Name Format"] = "1b) Ogiltigt Namnformat", diff --git a/modules/client_locales/locales.lua b/modules/client_locales/locales.lua index ecf69966..a3e3d82e 100644 --- a/modules/client_locales/locales.lua +++ b/modules/client_locales/locales.lua @@ -166,16 +166,20 @@ end -- global function used to translate texts function _G.tr(text, ...) if currentLocale then - if tonumber(text) then - -- todo: use locale information to calculate this. also detect floating numbers + if tonumber(text) and currentLocale.formatNumbers then + local number = tostring(text):split('.') local out = '' - local number = tostring(text):reverse() - for i=1,#number do - out = out .. number:sub(i, i) + local reverseNumber = number[1]:reverse() + for i=1,#reverseNumber do + out = out .. reverseNumber:sub(i, i) if i % 3 == 0 and i ~= #number then - out = out .. ',' + out = out .. currentLocale.thousandsSeperator end end + + if number[2] then + out = number[2] .. currentLocale.decimalSeperator .. out + end return out:reverse() elseif tostring(text) then local translation = currentLocale.translation[text]