is I18N possible in mods (gamestrings)

BollwerkBollwerk Join Date: 2009-04-15 Member: 67196Members
edited January 2016 in Modding
Hi,

recently someone was asking for NS2+ do be translated. I found that idea intriguing so I had a shot at it since it is hosted on github.

However my preliminary tests showed that there is a big issue:
Although the gamestrings folder is properly loaded and the strings defined in the language files are properly resolved when using
Locale.ResolveString("MY_CUSTOM_TEXT")
all previously defined string translations (from n2/gamestrings) had been cleared. Resulting in a rather ugly main menu showing only the keys instead of the translation values.

A workaround would be to take, and copy the current translation files while appending one's own custom strings. But each time NS2 updates one would have to check for changes in the translations and merge those into the mod-shipped files which is not feasible.

So the questions are:
1. Did I take a wrong turn? Is there a different approach one should take to introduce translatable strings in a mod?
2. If not (and this should be answered by devs) will we see gamestrings properly merging (expected behaviour would be appending+overriding) instead of clearing in the future?

Thanks and regards



Comments

  • PelargirPelargir Join Date: 2013-07-02 Member: 185857Members, Forum Moderators, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Supporter, Reinforced - Silver, WC 2013 - Silver, Forum staff
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    If you replace ANY NS2 asset file, you file will be used instead of the original.

    You have to add gamestrings to the file to include the extra translations. Or you'll end up with all your default NS2 gamestrings set to their call name as you have seen.

    Gamestrings cannot be hooked as they are text files, your only solution is to append them with the new data.
  • MendaspMendasp I touch maps in inappropriate places Valencia, Spain Join Date: 2002-07-05 Member: 884Members, NS1 Playtester, Contributor, Constellation, NS2 Playtester, Squad Five Gold, NS2 Map Tester, Reinforced - Shadow, WC 2013 - Shadow, Retired Community Developer
    You'd basically want to do your own translation functions independent of NS2's, because you cannot extend it like you can with the rest of the game, precisely because of the gamestrings files.
  • xDragonxDragon Join Date: 2012-04-04 Member: 149948Members, NS2 Playtester, Squad Five Gold, NS2 Map Tester, Reinforced - Shadow
    edited February 2016
    Afaik, you cant mod gamestrings anyways (unless thats been fixed at some point). Loading the game with the mod mounted (or with -game) functions differently in certain key aspects compared to having it mounted on server-join.

    I used something like this in classic, loading my own files with just the changes/additions and cached it all to a table.
    local oldLocaleResolveString = Locale.ResolveString
    function Locale.ResolveString(s)
        //determine users locale
        local locale = Locale.GetLocale()
        //check if we replace/add this string
        local modString = kClassicLocaleTable["enUS"][s]
        if modString then
            //classic adds or replaces this string
            //return locale specific string
            if kClassicLocaleTable[locale] then
                return kClassicLocaleTable[locale][s]
            end
            return modString 
        else
            return oldLocaleResolveString(s)
        end
    end
    
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    For me I just used to make custom gamestring files that worked fine in gorgecraft. I removed all unused NS2 calls and added my own, and it worked perfectly.
  • BollwerkBollwerk Join Date: 2009-04-15 Member: 67196Members
    edited February 2016
    Alright that explains it then. Thanks for the input. :)

    I think it is a pity that it does not seem to be on the agenda for extending the modding tools.

    So I personally will probably go with overloading the Locale.ResolveString function like xDragon said.
    It sounds like a reasonable approach since this feels as close to the core API as it would get.


    I was getting the impression that it was possible since the "sample mod" tutorial was shipping gamestrings as well.
    (http://forums.unknownworlds.com/discussion/comment/2239071/#Comment_2239071)

Sign In or Register to comment.