Announcement

Collapse
No announcement yet.

How to change a value in an array?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to change a value in an array?

    In a form, I want to change the value in an array.

    I added a PHP method lang_change:

    Code:
    $this-> Nm_lang [ 'lang_acc_fld_descriptn'] = "Jack description";

    I call this method in onScriptinit
    Code:
    lang_change();
    Unfortunately Nm_lang [ 'lang_acc_fld_descriptn'] does not change to my new value.
    Can you see what is wrong with my code above?

  • #2
    It looks like you are trying to change an array in the internals of the ScriptCase generated code of the application?
    If this is the case, perhaps ScriptCase sets the array later (again), overwriting your change. I am only speculating, not having looked at the generated code itself.

    In any case, you could try to move the code to the "OnLoad" event section instead. I have often various code not work in "OnScriptInit", which would work when moved to "OnLoad". Also consider trying to not use the method for a start, but hardcode it in. If that works, then try method or perhaps an internal library.
    Best regards,

    Frank

    Comment


    • #3
      Hi Frank

      Thanks for the suggestion. I tried this in onLoad:

      2016-07-14_9-57-45.jpg

      As I am showing the result immediately after setting it, I expect to see the new value.
      Instead I see the original value!

      Is there another way of assigning a value to this array?

      This is important because I need to change the English spelling of words for USA and Britain. For example, "Organization" works in the USA, but in Britain they want to see "Organisation" (s instead of z)!

      Is the $this line the correct way to change the array?


      Code:
      $this-> Nm_lang ['lang_acc_fld_descriptn'] = "Jack description";
      echo $this->Ini->Nm_lang['lang_acc_fld_descriptn'] ;

      Comment


      • #4
        Hi Jack,

        I never look deeper into or change the code generated by ScriptCase (although I do write libraries and other external stuff), so perhaps there is some obvious reason for your code. However, just looking at it it, it would seem that you are changing another array than the one that you are using echo on:
        There is an extra "->Ini" in your echo statement compared to the one where you set the array value.

        Btw, having to translate between very disparate languages in my applications, it seems like a true luxury problem that a few words are spelled differently in British and American English respectively, but I guess that they feel a need too distinguish these few differences.
        Last edited by Orion; 07-14-2016, 03:42 PM.
        Best regards,

        Frank

        Comment


        • #5
          Hi Jack,

          I had an idea on how you could possibly better handle the issue of British vs. American English. If you choose one of them as the core, you could create the other one as a language in the translation module and only specify translations for the phrases that contains the double spelling words, e.g. organisation. If a phrase is not translated to a given language it will fall back to the core.

          However, if you are only going to deliver your application in English, it is perhaps an overkill, but if you are anyway going to have other languages, that would be the way to do it.
          Best regards,

          Frank

          Comment


          • #6
            Originally posted by Orion View Post
            There is an extra "->Ini" in your echo statement compared to the one where you set the array value.
            Hi Frank

            Well spotted. That solved it! Hooray!!

            So now I can successfully change: Nm_lang ['lang_acc_fld_descriptn'] to "Jack description".


            I am interested in your suggestion:
            Originally posted by Orion View Post
            you could create the other one as a language in the translation module
            I don't know how to do that. Where is the translation module?

            I do see this:

            2016-07-15_15-50-40.jpg


            But all I can do with this is create a spreadsheet of phrases to send to Scriptcase. How do I add my own full language?


            Comment


            • #7
              Great that it worked!

              ----------------------------------

              The language/translation facilities in ScriptCase are quite good, but as far as I know there is, unfortunately, not a good comprehensive documentation or tutorial. One has to play to play a bit around with it. Having said that, I found it quite easy to get into. Basic steps:

              1. Open your project properties (menu Project -> Properties) and add the locales that you need, e.g. English (United States), English (Great Britain), German

              2. Then open Locales -> Application Language (as you have already done above).
              Here you can then select e.g. "ScriptCase Messages" -> "Validation" in the tree menu to the left, and the standard ScriptCase texts will be shown for your project's selected locales.
              If you put the variable {lang_errm_errt} as a label for a field or a message, ScriptCase will replace the variable with the appropriate language that has been selected at the installation (can be changed in the applications if you specify it)

              3. You can create new folders for various areas

              4. To use it to the fullest extend you can use Tools -> Data Dictionary which can create folder and language variables for you for your tables. When you do this and enter translations for the variables with the Application Language module (point 2 above), ScriptCase will automatically use these variables in new forms and grids that you create for the tables.
              However, if you only are going to release your application in English, it is probably sufficient to just use step 2/3 to create variables manually for those few texts that contain words, which are spelled differently in American and British English respectively.
              Best regards,

              Frank

              Comment


              • #8
                Thanks Frank.
                That looks good.

                The problem is that when I add both English (USA) and English (UK):

                2016-07-16_9-56-34.jpg

                ... it only adds one English!


                2016-07-16_9-59-20.jpg


                So I cannot use this feature to cater for different English spelling in USA and UK.
                Luckily I have the technique you helped me solve above!


                PS: If anyone knows how to add more than one English Language set, please let me know.

                Comment

                Working...
                X