Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Adding localization strings can specify if they should overwrite exis…
Browse files Browse the repository at this point in the history
…ting strings
  • Loading branch information
JamesWilko committed Apr 12, 2015
1 parent a1b27cd commit 85106b5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions mods/base/lua/LocalizationManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,29 @@ function LocalizationManager.text( self, str, macros )

end

function LocalizationManager:add_localized_strings( string_table )
function LocalizationManager:add_localized_strings( string_table, overwrite )

-- Should we overwrite existing localization strings
if overwrite == nil then
overwrite = true
end

if type(string_table) == "table" then
for k, v in pairs( string_table ) do
self._custom_localizations[k] = v
if not self._custom_localizations[k] or (self._custom_localizations[k] and overwrite) then
self._custom_localizations[k] = v
end
end
end

end

function LocalizationManager:load_localization_file( file_path )
function LocalizationManager:load_localization_file( file_path, overwrite )

-- Should we overwrite existing localization strings
if overwrite == nil then
overwrite = true
end

local file = io.open( file_path, "r" )
if file then
Expand All @@ -51,7 +65,7 @@ function LocalizationManager:load_localization_file( file_path )
file:close()

local contents = json.decode( file_contents )
self:add_localized_strings( contents )
self:add_localized_strings( contents, overwrite )

end

Expand Down

0 comments on commit 85106b5

Please sign in to comment.