Git Product home page Git Product logo

Comments (4)

jimmythompson avatar jimmythompson commented on September 18, 2024

In order to do this server-side, we'd need to take out all Dropplets hard-coded strings and replace them with a function, like so:

<a class="powered-by" target="_blank" href="http://dropplets.com"><img src="http://jimmythompson.co.uk/blog/dropplets/style/images/powered-by.png"></img>
      Powered by Dropplets
    </a>

... would become ...

<a class="powered-by" target="_blank" href="http://dropplets.com"><img src="http://jimmythompson.co.uk/blog/dropplets/style/images/powered-by.png"></img>
      <?php echo international("Powered by Dropplets"); ?>
    </a>

The international function would look like:

function international($key) {
    if(in_array($key, $translations)) {
        return $translations[$key];
    }

    return $key;
}

This way, should a translation not exist, the site will automatically default back to English.

from dropplets.

jazzsequence avatar jazzsequence commented on September 18, 2024

couldn't you just use gettext strings? (e.g. __(), _n, _e)

from dropplets.

jimmythompson avatar jimmythompson commented on September 18, 2024

That sounds like a much better idea. 👍

I didn't even know such a thing existed, my apologies.

from dropplets.

jazzsequence avatar jazzsequence commented on September 18, 2024

I only know i18n in a WordPress context, but the functions themselves are generic php functions. The basic idea is you wrap your test strings in a php function like the ones I've listed, so:

 <a class="powered-by" target="_blank" href="http://dropplets.com"><img src="http://jimmythompson.co.uk/blog/dropplets/style/images/powered-by.png"></img>
      <?php _e( 'Powered by Dropplets', 'dropplets' ); ?>
 </a>

Then when you run your code through gettext (e.g. with a translation program like Poedit, although you can do this with a php function as well), you tell it to look for _e and __ and _n and any other localization functions you're using and it will pull out those text strings that are wrapped in those functions and allow you to generate .po/.mo language files which can be used for translating the program.

There may be more that I'm not thinking of in terms of calling and initializing the language files because I haven't dug deep into how WordPress uses the language files once they are there, but the first step would be just getting it ready for gettext.

Note: your method isn't far off and could actually work if the function international was added to Poedit when you were creating the .pot file, but I don't think it would be strictly necessary unless there were things you were doing in the function that weren't being done otherwise (say stripping out html entities or something).

from dropplets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.