Search code examples
javaphpandroidcodeignitermultilingual

Multilanguage @ Server API + Android Application


I have Android Application which are supprting multilanguage (Russian & Latvian), no questions to this.

Problem is, that my backend is on CI and I have some definied Strings (mostly technical), example (Russian):

define('ALL_CAT',"Все категории");
define('NO_DATA',"Ничего нет.");

And if Application is in Latvian, then I will in any case see this Russian strings.

Is it possible somehow translate Backend CI Api Strings?

(Or, move all API string to client and show them from client - if this possible, idk)

PS: Also I have no saved Language on client side. It means if User open Application and select Latvian, use Application on Latvian, but when application closed/reopened user must select Latvian again ;-)

Thank you in advance,


Solution

  • Yes. The solution is to send a placeholder instead of russian.

    define('ALL_CAT',"placeholder::ALL_CAT");
    define('NO_DATA',"placeholder::NO_DATA");
    

    Then, whenever your client encounters a placeholder string:

    String recieved = getStringFromServer();
    if(recieved.indexOf("placeholder") == 0){
        recieved == //rusian or latvian.
    }
    

    You translate that placeholder string with a lookup table. You can define that lookup table in a file in your app, or in a database on a server somewhere.