Search code examples
androidlibgdx

Libgdx multiple language assets


I am making a game with libgdx where all game text is bitmap images. I want to use different asset images for different languages. For android you can put your assets under the res directory in the right locale code folder. but apparently there is no way to do something similar in libgdx.

Libgdx have some sort of managing strings but not game assets as i have found in the doc I18n & L10n.

After some digging I have found this class PrefixFileHandleResolver but I'm not quite sure if it is the right option or how to properly use it.

Any ideas? thanks in advance :D


Solution

  • You can use a FileHandleResolver as you thought. Just implement your own one by overriding

        @Override
        public FileHandle resolve(String fileName)
        {
            fileName = yourLogicToFindYourLanguageFile(fileName);
            return Gdx.files.internal(fileName);
        }
    

    Easiest use is with an AssetManager (which I would recommend you to use anyway) - just pass your own FileHandleResolver in AssetManager's constructor.