Owncloud 8 Translation in core/js deleted -> my Solution

Previous Topic Next Topic
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Owncloud 8 Translation in core/js deleted -> my Solution

This post has NOT been accepted by the mailing list yet.
This post was updated on .
I dont know who is writing the documentation in owncloud but i got frustrated in getting my own apps running after updating to 8.0 and think the documentation could be better. There could be something like a list of all changes in core. I had to look for errors in my apps and check the whole documentation if there is a change in this part of my code and the functions im using. This is a little bit frustrating especially if its not my own app I have to get running.  Or am I missing something?

I used the JavaScript function t() in core/js you just killed with a comment in the documentation "There is currently no good way to translate JavaScript strings". Hmm there was a way, not clean but there was. But I thought "ok just do it" and started programming as suggested in the documentation and think thats not clean neither.
Problem is that an ul with ids needs clean strings without whitespaces or things like "." So you can't add all translation key/value pairs and ask for an english string to be translated. Plus I don't want to add a list manually and think about keys of all translation strings.
Documentation is here https://doc.owncloud.org/server/8.0/developer_manual/app/l10n.html

Here is my solution:
in my Template:
<ul class="translation" id="someid">
    <?php foreach($l->getTranslations() as $key => $value) { ?>
        <li data-id="<?php echo $key; ?>"><?php echo $value; ?></li>
    <?php } ?>
This will add all translated things in your language file. Of course I'm hiding this per css.

Then I have a javaScript file I just require in my Template:
var t = function(ulId, dataId) {
    if($('#' + ulId).length > 0 && $('#' + ulId + ' *[data-id="' + dataId + '"]').length > 0) {
        return $('#' + ulId + ' *[data-id="' + dataId + '"]').text();
    return dataId ;
So if there is no translation you will get the dataId you asked for. In my case an english string because I call this function like:
t("someid", "to be translated");

I hope this will help someone. Maybe its a good solution and someone could change the documentation?
Reply | Threaded
Open this post in threaded view

Re: Owncloud 8 Translation in core/js deleted -> my Solution

The author has deleted this message.