Link to home
Get AccessLog in
Avatar of Daniele Brunengo
Daniele BrunengoFlag for Italy

asked on

How to capitalize each letter coming after a particular string

Hello, I'm editing a PO translation file for a Wordpress website.
The former translator forgot to capitalize most first letters in sentences.

POedit doesn't allow me to capitalize each first letter, so I thought I'd use Notepad++ (but feel free to suggest something else).

I need to select each letter coming after this particular string: msgstr "
and capitalize it.

Maybe with Regex, not an expert though. Can somebody lend a hand? Thanks.
Avatar of viki2000
Flag of Germany image

Are you OK with Microsoft Word?
If yes, could you paster here a reference text just as example?
Avatar of Daniele Brunengo


Here's an extract. All words after 'msgstr "' need to begin with a capital letter.

#: E:\!our theme
#: wordpress\residence\!versions\1.09\wpresidence/libs/property.php:458
msgid "Bedrooms: "
msgstr "camere da letto:"

#: E:\!our theme
#: wordpress\residence\!versions\1.09\wpresidence/libs/property.php:467
msgid "Bathrooms: "
msgstr "bagni:"

#: E:\!our theme
#: wordpress\residence\!versions\1.09\wpresidence/libs/property.php:550
#: wordpress\residence\!versions\1.09\wpresidence/templates/submit_templates/property_location.php:173
msgid "Place Pin with Property Address"
msgstr "posizionare Pin con indirizzo dell'immobile"

Open in new window

Could you confirm if after msgstr string is always space+quotation mark before the word that you want to capitalize starts?
Yes it is.
Then I guess one solution would be to import it in Microsoft Word and use some VBA code.
Search for the string <msgstr "> and then find the letter/character following that string. Then capitalize it.
I do not know all the steps now, but this is how I would do it.
The difficulty that I have now is to find the character after that string. The string itself is easy to find, but to specify the following letter I have no idea for the moment. The rest should not be so complicated.
Let's see what other people suggest. If in mean time I have a solution I will let you know.
Thanks. I think Regex should allow to select the following character, but I'm not sure.
The regex find pattern should be simple enough.
\. +[a-z]

The replacement will depend on the tool you are using.
This pattern is a bit more inclusive:
(?:^|\. +)([a-z])
you could use the macro Recorder in visual Studio (download vs express or vs community for free if not available).

open the text file in the vs text editor.

CTRL+SHIFT+R   starts the macro Recorder
CTRL+F         opens search window
msgstr "       enter this at Find What
               check find options 'Match case' and 'Match whole word'
F3             leaves find window and selects search string
<--            cancels selection 
CTRL+-->       moves text cursor to " without selection
-->            moves to first character after "
CTRL+SHIFT+U   capatalizes first character after "
CTRL+SHIFT+R   ends macro recording

Open in new window

now you could use the macro by CTRL+SHIFT+P until all occurrences were changed.

note, of course you could use any macro recorder for this task. some control sequences may differ, though.

Simplest solution:
$text = "Your file's contents";
$Text = str_replace('['msgstr "a','msgstr "b','etc',],['msgstr "A','msgstr "B','Etc',],$text);

Open in new window

str_replace() will replace each occurrence of a string in the first array with the equivalent string in the second array by position.

You could use a loop to create the arrays first to cut down on typing.
If you have Notepad++ with the TextFX plug-in installed, you can select all the text and do the following on the menu bar:
TextFX | TextFX Characters | Sentence Case

Note: The "|" represents the appearance of a sub menu
Avatar of William Nettmann
William Nettmann
Flag of South Africa image

Link to home
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
That worked great. It was the only solution to actually solve the problem in one step. I thank you all for your input.