[manifest]
version = "1.0.0"
dump_lua = true
priority = -10

### Language API

# Game:set_language()
[[patches]]
[patches.pattern]
target = 'game.lua'
pattern = "if not (love.filesystem.read('localization/'..G.SETTINGS.language..'.lua')) or G.F_ENGLISH_ONLY then"
position = 'at'
payload = 'if false then'
match_indent = true

[[patches]]
[patches.pattern]
target = 'game.lua'
pattern = "local localization = love.filesystem.getInfo('localization/'..G.SETTINGS.language..'.lua')"
position = 'at'
payload = "local localization = love.filesystem.getInfo('localization/'..G.SETTINGS.language..'.lua') or love.filesystem.getInfo('localization/en-us.lua')"
match_indent = true

[[patches]]
[patches.pattern]
target = 'game.lua'
pattern = "self.localization = assert(loadstring(love.filesystem.read('localization/'..G.SETTINGS.language..'.lua')))()"
position = 'at'
payload = """self.localization = assert(loadstring(love.filesystem.read('localization/'..G.SETTINGS.language..'.lua') or love.filesystem.read('localization/en-us.lua'), '=[localization "'..G.SETTINGS.language..'.lua"]'))()"""
match_indent = true

[[patches]]
[patches.pattern]
target = 'game.lua'
pattern = "self.LANG = self.LANGUAGES[self.SETTINGS.language] or self.LANGUAGES['en-us']"
position = 'at'
payload = "self.LANG = self.LANGUAGES[self.SETTINGS.real_language or self.SETTINGS.language] or self.LANGUAGES['en-us']"
match_indent = true

# G.FUNCS.change_lang

[[patches]]
[patches.pattern]
target = 'functions/button_callbacks.lua'
pattern = "G.SETTINGS.language = lang.key"
position = 'at'
payload = """G.SETTINGS.language = lang.loc_key or lang.key
G.SETTINGS.real_language = lang.key"""
match_indent = true

# G.FUNCS.warn_lang (wtf)
[[patches]]
[patches.pattern]
target = 'functions/button_callbacks.lua'
pattern = 'if (_infotip_object.config.set ~= e.config.ref_table.label) and (not G.F_NO_ACHIEVEMENTS) then'
position = 'at'
payload = 'if (_infotip_object.config.set ~= e.config.ref_table.label) then'
match_indent = true
