LangEditor

13 May

LangEditor

I do quite a bit of work on multi-lingual sites, and as a polyglot myself, I love the i18n features of SilverStripe. One thing that comes up quite frequently is that a client wants to edit the translations for static text (i.e. the _t() function calls) on the website. While the Translatable module affords content editors the ability to edit dynamic text in the CMS, static text remains buried in cryptic PHP, left editable only by a PHP developer or a very well-instructed content editor.

In an effort to help our these clients and make my life a lot easier, I created a little module last year to support creating, editing, and filtering PHP language files from within the CMS in an abstraction of the original PHP file.

This module is on my Github at git://github.com/unclecheese/LangEditor.git

Take a look! Post your feedback! Enjoy LangEditor!

 

14 Responses to “LangEditor”

  1. Stijn De Lathouwer 13. May, 2011 at 12:11 pm #

    That looks great. Will be using that on a lot of sites, I think. Does it work for just the lang folder in mysite? Or also for lang files in module folders?

    • unclecheese 13. May, 2011 at 12:20 pm #

      Just the mysite (or $project) folder for now. Allowing translations of thirdparty modules raises many, many questions. :)

  2. Olivier Titeca 17. May, 2011 at 4:51 am #

    Hi Uncle Cheese,
    I’m following your work for a while, and youare doing great job.
    By the while, international websites with Silverstripe is a real nightmare.
    I had to code extensions and modify so much things in the original code of silverstripe to be able to really have an international website running.
    So one day, i’ll take time to post all my code, i have to take time to do it.

    Certainly, i’ll propose an article to you as soon as i review all the code i wrote.
    The core CMS framework need major update in all parts including the JS files to be fully translatable.

    • unclecheese 17. May, 2011 at 11:41 am #

      Wow. I can’t imagine having that much trouble. Certainly not so much that I would have to make changes to the source code. Sounds like you were missing some of the fundamentals.

      • otiteca 09. Jun, 2011 at 11:33 am #

        ok, have you ever try to have the same widget translated for each translated page where that widget is present.

        good luck.
        without hacking the core source you cannot, just because the JS have not been plan to handle multilingual.

        Another one:
        the Model Admin do not handle multilingual.
        I did have to hack that also, simply because i use it.
        Well at the end i did have something functional, but not without hacking.

        • otiteca 30. Nov, 2012 at 8:28 am #

          More than a year ago i made this previous post.
          this have nothing to do with your langeditor, but the latest 3.0.3 version is worst that what we have a year ago for translation purpose.

          The translatable module is sucking, Silverstripe now is created for english spoken only people, as it’s too buggy to support an additional language.

          I just figured out, that i have so much to debug now in this new core source…

  3. Arda 20. May, 2011 at 6:14 am #

    Thank you Uncle Cheese. We will be using it too. I agree that it’s not so problematic to have a multi lingual web site with Silverstripe After the release of 2.4 I usually use SiteConfig to store static texts.

  4. Pipifix 17. Jun, 2011 at 12:18 pm #

    Hi UncleCheese.
    First of all thanks for you this fine and useful modul and the allover help for the ss-community. I wanna use the lang-editor but got some issues. After installing the modul in a regular way, the module responded that there is no german language (default locale) file. So I made a ‘lang’folder in the mysite folder and created a file called ‘de_DE.php’.
    All I get is a blank admin page by switching to the module. What did i wrong. How to solve this issue?
    Thanks and greetings from Germany.

    Pipifix

  5. Adam 31. Oct, 2011 at 10:56 am #

    Hi UC,

    As usual great work, just wondering if you have this working in 2.4 install. I had to make some changes to the LangEditor.php file to make it work, and then it is still not displaying correctly, just wondering if you have any later work then what is on the git?

    Changes I made where to line 138 the STR variable was an array to a str so it gave the old “Array to string” error. I changed the line to ‘EntityField’ => new TextField(“t[$locale][$namespace][$entity]”,””,stripslashes($str[0])),
    This seemed to fix the problem and looks like it is displaying the information you would expect it too.

    Now i just don’t have any scroll bars or save button in my left and main :( Any help would be fantastic the site i am working on is a huge multi lingual site so this module would help the client substantially.

  6. Adam 31. Oct, 2011 at 11:12 am #

    My Bad, found the issue the path for the requirements was
    lang_editor and i installed in the folder LangEditor so of course it would not work. Sorry nice job again.

  7. mauricio 15. Mar, 2012 at 10:34 am #

    hi unclecheese! first of all congrats man, you’re THE unclecheese :) i learn so much from you!
    when i install it throws me this error!

    mysite\lang\en_US.php does not exist!

  8. Adam 11. Jun, 2012 at 10:32 am #

    Hey Uncle Cheese

    I had some issues with the LangEditor and the lang files generated from the SilverStripe i18nTextCollectorTask.

    They Generate items with an array if its been added by the system or just a string if its recieved the value from a exsiting _t function.
    for example.

    $lang[‘en_US’][‘Blockout’][‘Date’] = ‘Date';
    $lang[‘en_US’][‘Blockout’][‘PLURALNAME’] = array(
    ‘Blockouts’,
    50,
    ‘Pural name of the object, used in dropdowns and to generally identify a collection of this object in the interface’
    );

    THere for when the LangEditor phased through the content it would only out put D (incorrect) for the Date and Blocksouts (correct) for the PLURALNAME.

    To fix this I change the code at line 135 from this
    $entities->push(new ArrayData(array(
    ‘Entity’ => $entity,
    ‘EntityField’ => new TextField(“t[$locale][$namespace][$entity]”,””,stripslashes($str[0])),
    ‘Namespace’ => $namespace
    )));

    to this

    if(is_array($str)){
    $entityField = stripslashes($str[0]);
    } else {
    $entityField = stripslashes($str);
    }
    $entities->push(new ArrayData(array(
    ‘Entity’ => $entity,
    ‘EntityField’ => new TextField(“t[$locale][$namespace][$entity]”,””,$entityField),
    ‘Namespace’ => $namespace
    )));

    I hope that makes sense and this is the correct place to bring this up let me know if you need it posted to a ticket somewhere. Keep up the awesome work :)

  9. bk 09. Jul, 2012 at 11:43 pm #

    I have integrated this module in my site,i wonder if this module work for the javascript validations?

Trackbacks and Pingbacks

  1. An Update On SilverSmith: Translations, Template Genius, and more! | Left and Main - 17. Nov, 2011

    […] editor for managing all your translation files. A majority of this utility is a port from the LangEditor module I released earlier this year. With the Translation Editor, you can create new translation […]