L10n - best practice handling dynamic language dependent texts


I have a question which is surely answered somewhere but I didn’t find it.
I want to create an language specific admin gui for a nc plugin.
The admin should be able to define menu texts for different languages.

According to Translation — Nextcloud latest Developer Manual latest documentation one solution could be to let nc do the job. If translations are missing, some background processes are provided to automatically enhance the translations via code inspection.

In my case the admin defines the texts dynamically, evtl. user specific.
I. e. the texts have to be translated on the fly or the admin has to provide the language specific texts himself.

Is there a best practice that the admin provides the text by using nc existing routines?
E.g. enhancing nls files?

Thanks for your help,

It’s far from trivial.

Check out the code from GitHub - nextcloud/terms_of_service: 📜 Requires users to accept the terms of service before accessing data.

Basically you need to add a language selection for the admin and then store it for each language manually:

Provides the language list
It comes from:

The admin selects it in

And it’s stored with the text the admin provided:

Thanks for your answer. I’m a complete newbie to nc, php, therefore I didn’t understand the solution.

I cannot expect you to explain the code. Perhaps you can give me a more conceptual answer.
Where does nc store the admin’s texts? (files, DB, …)
In case of files: Are the files reread for every access or only at nc startup?

I know Java’s NLS concept. Text’s are stored in language/country specific NLS files.
Texts are selected via package name/ID and the language/country parameters.
If the specific NLS file does not exist, a default file is taken.

I think for user specific texts which should be changable effectivly within a user session, the file concept is not the best way (don’t know whether files are cached, read at every access, …).
DB should be better. Does nc offers sth for this purpose? Do one have to implement it himself?

Thanks for your patience.

Your app has to take care of storing and reading the value.
Since we are in php (non-persistent) I would recommend to store it in the database (like the terms of service app does).

If you are new to php, maybe it makes sense to work through the tutorial first: