![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Resource strings I'm trying to find some info on how people are handling resource strings or what the recommended way is. All of the strings for the cmdlets are localized (verbose and error message strings) and there are a number of cmdlets in the snap-in so I'd like to have one resource file or xml file that has the strings for each cmdlet. somethiing like... <cmdlet name="Get-AAAA"> <string name="string1" value="string1 text"> <string name="string2" value="string2 text"> </cmdlet> <cmdlet name="Get-BBBB"> <string name="string1" value="string1 text"> <string name="string2" value="string2 text"> </cmdlet> so in the cmdlet when I need a string I could do... WriteVerbose(GetResourceString("Get-BBBB", "string2")); has anyone done something like this? Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Resource strings On Mar 3, 3:25 pm, Jarlaxle <Jarla...@xxxxxx> wrote: Quote: > I'm trying to find some info on how people are handling resource strings or > what the recommended way is. > > All of the strings for the cmdlets are localized (verbose and error message > strings) and there are a number of cmdlets in the snap-in so I'd like to have > one resource file or xml file that has the strings for each cmdlet. > somethiing like... > > <cmdlet name="Get-AAAA"> > <string name="string1" value="string1 text"> > <string name="string2" value="string2 text"> > </cmdlet> > <cmdlet name="Get-BBBB"> > <string name="string1" value="string1 text"> > <string name="string2" value="string2 text"> > </cmdlet> > > so in the cmdlet when I need a string I could do... > > WriteVerbose(GetResourceString("Get-BBBB", "string2")); > > has anyone done something like this? > > Thanks. other .NET application. In Pscx ( http://www.codeplex.com/powershellcx ), we use .NET 2.0's strongly typed resources whereever we can. You should download the source and have a look; for example, from one of my compression cmdlet's base classes: ( http://www.codeplex.com/PowerShellCX...ngeSetId=30984 ) abstract class WriterBase<TCommand, TStream> : IArchiveWriter where TCommand : WriteArchiveCommandBase where TStream : Stream { // ... protected bool ShouldClobber(string path) { if (Command.NoClobber.IsPresent) { FileInfo file = new FileInfo(path); Command.WriteWarning(String.Format(Properties.Resources.ArchiveOutputAlreadyExists, file.Name)); return false; } return true; } As you can see, we just keep format strings in the resources file. At some point in the future, we will move them into a separate satellite assembly to allow localisation of Pscx. Hope this helps, - Oisin Microsoft MVP http://www.nivot.org/ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Resource strings Thanks for the info. I wasn't sure if there was a recommended different way since the cmdlet class has a GetResourceString method. "Oisin (x0n) Grehan [MVP]" wrote: Quote: > On Mar 3, 3:25 pm, Jarlaxle <Jarla...@xxxxxx> > wrote: Quote: > > I'm trying to find some info on how people are handling resource strings or > > what the recommended way is. > > > > All of the strings for the cmdlets are localized (verbose and error message > > strings) and there are a number of cmdlets in the snap-in so I'd like to have > > one resource file or xml file that has the strings for each cmdlet. > > somethiing like... > > > > <cmdlet name="Get-AAAA"> > > <string name="string1" value="string1 text"> > > <string name="string2" value="string2 text"> > > </cmdlet> > > <cmdlet name="Get-BBBB"> > > <string name="string1" value="string1 text"> > > <string name="string2" value="string2 text"> > > </cmdlet> > > > > so in the cmdlet when I need a string I could do... > > > > WriteVerbose(GetResourceString("Get-BBBB", "string2")); > > > > has anyone done something like this? > > > > Thanks. > Adding resource strings to Cmdlets shouldn't be any different than any > other .NET application. In Pscx ( http://www.codeplex.com/powershellcx > ), we use .NET 2.0's strongly typed resources whereever we can. You > should download the source and have a look; for example, from one of > my compression cmdlet's base classes: > > ( http://www.codeplex.com/PowerShellCX...ngeSetId=30984 > ) > > abstract class WriterBase<TCommand, TStream> : IArchiveWriter > where TCommand : WriteArchiveCommandBase > where TStream : Stream > { > > // ... > > protected bool ShouldClobber(string path) > { > if (Command.NoClobber.IsPresent) > { > FileInfo file = new FileInfo(path); > > Command.WriteWarning(String.Format(Properties.Resources.ArchiveOutputAlreadyExists, > file.Name)); > return false; > } > return true; > } > > As you can see, we just keep format strings in the resources file. At > some point in the future, we will move them into a separate satellite > assembly to allow localisation of Pscx. > > Hope this helps, > > - Oisin > > Microsoft MVP > http://www.nivot.org/ > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Resource strings On Mar 4, 11:38*am, Jarlaxle <Jarla...@xxxxxx> wrote: Quote: > Thanks for the info. *I wasn't sure if there was a recommended differentway > since the cmdlet class has a GetResourceString method. > > "Oisin (x0n) Grehan [MVP]" wrote: > > > Quote: > > On Mar 3, 3:25 pm, Jarlaxle <Jarla...@xxxxxx> > > wrote: Quote: > > > I'm trying to find some info on how people are handling resource strings or > > > what the recommended way is. Quote: Quote: > > > All of the strings for the cmdlets are localized (verbose and error message > > > strings) and there are a number of cmdlets in the snap-in so I'd like to have > > > one resource file or xml file that has the strings for each cmdlet. > > > somethiing like... Quote: Quote: > > > <cmdlet name="Get-AAAA"> > > > * * <string name="string1" value="string1 text"> > > > * * <string name="string2" value="string2 text"> > > > </cmdlet> > > > <cmdlet name="Get-BBBB"> > > > * * <string name="string1" value="string1 text"> > > > * * <string name="string2" value="string2 text"> > > > </cmdlet> Quote: Quote: > > > so in the cmdlet when I need a string I could do... Quote: Quote: > > > WriteVerbose(GetResourceString("Get-BBBB", "string2")); Quote: Quote: > > > has anyone done something like this? Quote: Quote: > > > Thanks. Quote: > > Adding resource strings to Cmdlets shouldn't be any different than any > > other .NET application. In Pscx (http://www.codeplex.com/powershellcx > > ), we use .NET 2.0's strongly typed resources whereever we can. You > > should download the source and have a look; for example, from one of > > my compression cmdlet's base classes: Quote: Quote: > > * *abstract class WriterBase<TCommand, TStream> : IArchiveWriter > > * * * *where TCommand : WriteArchiveCommandBase > > * * * *where TStream : Stream > > * *{ Quote: > > * * * *// ... Quote: > > * * * *protected bool ShouldClobber(string path) > > * * * *{ > > * * * * * *if (Command.NoClobber.IsPresent) > > * * * * * *{ > > * * * * * * * *FileInfo file = new FileInfo(path); Quote: > > Command.WriteWarning(String.Format(Properties.Resources.ArchiveOutputAlread*yExists, > > file.Name)); > > * * * * * * * *return false; > > * * * * * *} > > * * * * * *return true; > > * * * *} Quote: > > As you can see, we just keep format strings in the resources file. At > > some point in the future, we will move them into a separate satellite > > assembly to allow localisation of Pscx. Quote: > > Hope this helps, Quote: > > - Oisin Quote: > - Show quoted text - just that I prefer the intellisense you get with the strongly typed system. It's like visual studio autogenerates constants for your resource IDs. - Oisin |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| question regarding strings | PowerShell | |||
| Using $ signs in strings | PowerShell | |||
| -f paramater in strings | PowerShell | |||
| Comparing strings - is it a bug? | PowerShell | |||