• Login
Community
  • Login

Change language to specific user defined language

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
user-defined lalanguages
9 Posts 4 Posters 935 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    Dustin riddick
    last edited by Feb 28, 2024, 4:13 PM

    I’ve been attempting to change the language to a specific user defined language for certain txt files by name. Currently all I can find is nppm_setcurrentlangtype which changes to a user defined language but not the correct language. It seems all user defined are type 15 L_USER. There is nppm_getnbuserlang however I don’t see what use this information gives me.

    M C 2 Replies Last reply Feb 28, 2024, 4:21 PM Reply Quote 0
    • M
      Michael Vincent @Dustin riddick
      last edited by Feb 28, 2024, 4:21 PM

      @Dustin-riddick said in Change language to specific user defined language:

      I’ve been attempting to change the language to a specific user defined language for certain txt files by name.

      How - are you developing a plugin, or are you using an existing scripting plugin (e.g., NppExec, PythonScript)? Both of the latter scripting plugins offer a “run Notepad menu command” command - which you could use to activate your UDL by calling it by name under the “Language” menu.

      Example NppExec (I have an ‘NppExec’ UDL):

      NPP_MENUCOMMAND Language\NppExec
      

      Cheers.

      D 1 Reply Last reply Feb 28, 2024, 4:31 PM Reply Quote 0
      • D
        Dustin riddick @Michael Vincent
        last edited by Dustin riddick Feb 28, 2024, 4:52 PM Feb 28, 2024, 4:31 PM

        @Michael-Vincent I’m developing in c++. I just downloaded the template and haven’t looked into any additional scripting engines. I hadn’t seen nppm_memucommand so I will attempt to use that

        M 1 Reply Last reply Feb 28, 2024, 5:01 PM Reply Quote 0
        • M
          Michael Vincent @Dustin riddick
          last edited by Michael Vincent Feb 28, 2024, 5:05 PM Feb 28, 2024, 5:01 PM

          @Dustin-riddick

          That won’t work - it is not a Notepad++ API; rather, made available in the existing scripting plugins. Hence why I asked. I think you’ll need a more “convoluted” method to do it via the Notepad++ API.

          Note you can rather easily get the language type (again, NppExec example using standard N++ API calls):

          NPP_SENDMSG NPPM_GETCURRENTLANGTYPE 0 @0
          SET LANGTYPE = $(MSG_LPARAM)
          NPP_SENDMSG NPPM_GETLANGUAGENAME $(LANGTYPE) @""
          SET LANGNAME = $(MSG_LPARAM)
          NPP_SENDMSG NPPM_GETLANGUAGEDESC $(LANGTYPE) @""
          SET LANGDESC = $(MSG_LPARAM)
          

          Which for my NppExec UDL, produces:

          ================ READY ================
          \lang
          type = 15
          name = udf - NppExec
          desc = User Defined language file - NppExec
          ================ READY ================
          

          But I don’t see how to “set” the language once you know the UDL sub-type.

          Cheers.

          P D 2 Replies Last reply Feb 28, 2024, 5:24 PM Reply Quote 0
          • P
            PeterJones @Michael Vincent
            last edited by Feb 28, 2024, 5:24 PM

            @Michael-Vincent said in Change language to specific user defined language:

            it is not a Notepad++ API

            NPP_MENUCOMMAND may be an NppExec nomenclature, but the API has a corresponding message that works with IDM values, not menu name.

            NPPM_MENUCOMMAND , where the wParam is 0 and lParam is the IDM constant. I explained in this recent post how to find the menuCmdID in the source for builtin languages, or using NppUISpy for UDL (the macro I was showing there is using the NPPM_MENUCOMMAND message)

            1 Reply Last reply Reply Quote 2
            • D
              Dustin riddick @Michael Vincent
              last edited by Feb 28, 2024, 5:42 PM

              @Michael-Vincent

              Hmm I was able to set the desired language on my computer with this method. The issue I have now is I have to iterate through the user languages set to a language and then check the name of the language to see if it’s the one I want. I can’t seem to get a specific menu option by name

              C 1 Reply Last reply Feb 28, 2024, 5:55 PM Reply Quote 0
              • C
                Coises @Dustin riddick
                last edited by Coises Feb 28, 2024, 5:57 PM Feb 28, 2024, 5:55 PM

                @Dustin-riddick

                I haven’t had occasion to try this, but I believe that to get the correct menu id you’d need to scan the Languages menu. (There’s no reason to think it would be the same for different users; maybe not even for the same user over time.) Use NPPM_GETMENUHANDLE with wParam = 1 to get the main menu handle. From there it should be possible to find the menu entry you need with GetMenuItemInfo . The wID member of the MENUITEMINFO structure should give you the command ID to send.

                P 1 Reply Last reply Feb 28, 2024, 6:09 PM Reply Quote 1
                • P
                  PeterJones @Coises
                  last edited by Feb 28, 2024, 6:09 PM

                  @Coises said in Change language to specific user defined language:

                  There’s no reason to think it would be the same for different users; maybe not even for the same user over time.

                  In regards to the UDL section of the Language menu, correct. (The builtin languages will of course have the same IDM across any installation.)

                  @Dustin-riddick ,

                  My original suggestion was more in the thought of showing how to find the right menuCmdId for a UDL in a single-user environment; I wasn’t thinking in terms of a generic plugin (though I should have been – sorry). So yes, as @Coises has said, you will have to scan through the entries in the Language menu to find the one that has the right name, and use the win32 data structure he mentioned in order to find the associated menuCmdId that goes with it.

                  1 Reply Last reply Reply Quote 0
                  • C
                    Coises @Dustin riddick
                    last edited by Feb 28, 2024, 6:55 PM

                    @Dustin-riddick said in Change language to specific user defined language:

                    There is nppm_getnbuserlang however I don’t see what use this information gives me.

                    I think it does give you something helpful: the starting menu id for user-defined languages, and the number of user-defined languages . (I haven’t checked, but “starting number” implies they are consecutive.)

                    As described here , you can access menu items by id and Windows will traverse the menu structure. So once you know the first id and the number of ids (from NPPM_GETNBUSERLANG ) and the handle of the main menu (from NPPM_GETMENUHANDLE ), you can use GetMenuItemInfo to find the string associated with each until you either find the one you need or run out of entries.

                    1 Reply Last reply Reply Quote 0
                    6 out of 9
                    • First post
                      6/9
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors