Jump to content

Visual Studio Tools for KSP : Localization Helper


Recommended Posts

In working on Localization for my mods I was finding it sorta tedious to correlate all the numbers/files etc so I indulged myself in spending some time on something I've always wanted to do: creating a Visual Studio Extension.

Currently this has a single focus - which is speeding up the replacement of strings with localizer calls, but with enough time will add in any useful additions.

So What does it do?

In a nutshell it does this (cause pictures give you a better score right?):

RefactorPreviewOnly.png

It makes it a bit easier to replace strings in your code with Localizer.Format calls. When its actioned it:

  • Replaced the string under the cursor with the Localizer.Format call that has the next tag injected
  • Made sure that the usings statement is in the top of the file
  • Added comment to the end of the line to say what the tag equals do you can still search your code for the text
  • Written the key/values to the cfg files you configure
  • Updated the ID in the settings so we can move straight to the next one
  • Recorded the steps errors to a custom output pane

With this I can now run through and refactor strings, and write the cfg files, using the native VS refactoring toolset.

I've published it in a git hub repo with an MIT license as per usual modding rules and will add any other features/functions I can come up with that help too.

Lots more info on the wiki.

Links and Further Info

DT-OSILogo16.png This work is licensed under an MIT license as outlined at the OSI site

Link to comment
Share on other sites

I worked with this tool this morning.  I like it.  The only issue I found with it was that it did not recognize interpolated strings.  The work around is to revert the string interpolation to a string.Format.  It then recognizes and localizes the string.  This is definitely a huge time saver.  I'd done 2 other mods before this and it took a lot longer :P

A feature I would like to see, although with translations, I'm not sure how viable it is (given the contextual nature of some languages), would be to avoid duplicate strings in the localization file.  If 2 strings are identical, use the previously created id and avoid an additional string in the localization file.

Edited by Papa_Joe
Link to comment
Share on other sites

5 hours ago, Papa_Joe said:

I worked with this tool this morning.  I like it.  The only issue I found with it was that it did not recognize interpolated strings.  The work around is to revert the string interpolation to a string.Format.  It then recognizes and localizes the string.  This is definitely a huge time saver.  I'd done 2 other mods before this and it took a lot longer :P

A feature I would like to see, although with translations, I'm not sure how viable it is (given the contextual nature of some languages), would be to avoid duplicate strings in the localization file.  If 2 strings are identical, use the previously created id and avoid an additional string in the localization file.

Can you whack me an example line of an interpolated string you had and I can try and hook it up?

Imma try and get it so it can replace a parameterized string.Format in the next week too, but that's another story :P

Reusing keys is something that I'm not 100% sure on myself. I have most of the code for it, but I left it out intentionally because of translations. One of the things we saw in the stock translation is even if the same word is in used in English its not always the same word in all the other languages. We had to go back and redo a number of keys to make extra ones due to this context, Ill see about putting it in as an option, but you do need to beware of the context

EDIT: Just realized you said about the context stuff too - sorry :P

Link to comment
Share on other sites

3 hours ago, TriggerAu said:

Can you whack me an example line of an interpolated string you had and I can try and hook it up?

Imma try and get it so it can replace a parameterized string.Format in the next week too, but that's another story :P

Reusing keys is something that I'm not 100% sure on myself. I have most of the code for it, but I left it out intentionally because of translations. One of the things we saw in the stock translation is even if the same word is in used in English its not always the same word in all the other languages. We had to go back and redo a number of keys to make extra ones due to this context, Ill see about putting it in as an option, but you do need to beware of the context

EDIT: Just realized you said about the context stuff too - sorry :P

Ya, I was also concerned about the translation issues when thinking about the duplicate strings.  Good to know that you had considered it.  String example below:

 - GUILayout.Label($"Part {part.partinfo.title} is missing Kerbal {kerbal.name}", labelStyle, GUILayout.Width(150));

I recently switched over all my mods to using string interpolation.  So, while not painful, it was an extra step to revert back to a string.Format.  Likely the best solution is to convert it to a string.Format and replace the objects in the bracket with indexes, then localize the string portion.

All in all a very useful extension.  Thanks for taking the time to build this.

 

Update:  Another thing I noted is that if you undo a localization in the code editor, the localization file does not update.  This results in orphaned strings in the localization file.  It does not break anything, but does cause confusion and potentially additional work for needless translations.

With that said, if you alter your numbering in the localization file and you wish for the counts to be consistent, be sure to update the NextProjectID in the .ksplocalizer.settings file, found in your project root. and restart your project.

Edited by Papa_Joe
Grammar, clarifications
Link to comment
Share on other sites

On 6/12/2017 at 10:34 AM, Papa_Joe said:

...

Update:  Another thing I noted is that if you undo a localization in the code editor, the localization file does not update.  This results in orphaned strings in the localization file.  It does not break anything, but does cause confusion and potentially additional work for needless translations.

With that said, if you alter your numbering in the localization file and you wish for the counts to be consistent, be sure to update the NextProjectID in the .ksplocalizer.settings file, found in your project root. and restart your project.

Ill see if I can hook the undo path, but not sure. You can however simply edit the NextID in the settings window (which updates the file) and the next use of a tag in the file will replace the contents for you

eg Settings window says nextID = 1... Refactor string for id 1... you press Ctrl-Z , Simply change the nextID value in the settings window to 1 again and on you go - it will update the #autoloc...1 tag when you do the next refactor

Link to comment
Share on other sites

3 hours ago, TriggerAu said:

Ill see if I can hook the undo path, but not sure. You can however simply edit the NextID in the settings window (which updates the file) and the next use of a tag in the file will replace the contents for you

eg Settings window says nextID = 1... Refactor string for id 1... you press Ctrl-Z , Simply change the nextID value in the settings window to 1 again and on you go - it will update the #autoloc...1 tag when you do the next refactor

Thanks.   And here I went under the hood without thinking about the settings window.... :P 

Update:  I just wanted to say, with or without any action on the suggestions and observations, this is a good tool.  saved me loads of time.

Edited by Papa_Joe
additional comments
Link to comment
Share on other sites

  • 9 months later...
  • 2 years later...
  • 2 weeks later...
16 hours ago, TriggerAu said:

Updated this tonight with some edits that make it installable for VS2019 and avoid possible errors in the startup

I installed it on VS2019, got an error (I posted an issue about it).

https://github.com/TriggerAu/VSToolsForKSP/issues/3

I'm not sure if the issue is the problem, but when I right-click over a string, I don't see anything related to this.  I did verify that it was installed

Link to comment
Share on other sites

7 hours ago, linuxgurugamer said:

I installed it on VS2019, got an error (I posted an issue about it).

https://github.com/TriggerAu/VSToolsForKSP/issues/3

I'm not sure if the issue is the problem, but when I right-click over a string, I don't see anything related to this.  I did verify that it was installed

Damn , I see that now too, but not yesterday, apologies mate Ill get it nailed if it kills me

Link to comment
Share on other sites

22 minutes ago, TriggerAu said:

Damn , I see that now too, but not yesterday, apologies mate Ill get it nailed if it kills me

Let me add that I installed it into VS 2017, and have the same issue.

No rush for me, I've survived long enough with out :D

Appreciate all you do

Edited by linuxgurugamer
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...
  • 9 months later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...