Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Resource strings

Reply
 
Old 03-03-2008   #1 (permalink)
Jarlaxle


 
 

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 SpecsSystem Spec
Old 03-04-2008   #2 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

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.
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 SpecsSystem Spec
Old 03-04-2008   #3 (permalink)
Jarlaxle


 
 

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 SpecsSystem Spec
Old 03-04-2008   #4 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

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:

> > * *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:

> > Microsoft MVP
> >http://www.nivot.org/- Hide quoted text -
>
> - Show quoted text -
No problem. Ultimately they both use the same underlying system. It's
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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46