Reply to topic  [ 10 posts ] 
Aplying bold, italic, normal without using menu 
Author Message

Joined: 2009-09-04 13:11:25
Posts: 28
Hi again,

This very simple. Up to now, when I want to apply a bold attribute I just write "Bold" in the macro. However, when I change the language of my computer (from english to french), the names in the format menu are not the same and the macro doesn't work anymore. Also, sometimes I would like to make sure that the found expressions is neither bold or italic but there is no "regular" command in the format menu and the macro does not seem to find the commands in the tooldrawer. For me, it would be also useful to know how to apply "superscript", "subscript", "underline", etc. to a found expression.

Thank you,

Pat


2009-12-08 06:12:42
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
At some point it might be good to know what you are trying to do with your macro. I generally try to write my macros so they work with the kinds of things that Nisus can do easily.

Previously Henry suggested using Find and Replace to apply the formatting directly. Note that when you do it that way you in fact won't have any problem with the localization. So

Code:
Find and Replace $findstring, '\0', 'EaU'


will apply any formatting that you apply to the '\0' string. This will work for subscript as well as for bold, italic, etc. A limitation is however that this does not work to *remove* such formatting.

A more elaborate coding solutions could be done with the "Localize" command like this:
Code:
$doBold = Localize “Bold”
Menu $doBold


I haven't really tested this with another language, but if it works as advertised it should translate the "Bold" string into your current language.

To turn "bold" etc. off you could first check the menu with the "Menu State" command so the following will turn bold off.
Code:
If Menu State “Bold”
Bold
end


But overall I am wondering whether you might not be better off working with (user defined) styles. The style names will be immune to localization, and you can easily change their definitions to get different results. You could keep the set of styles in a style library. It's very easy to import a whole collection of styles that way. Styles are also exclusive, which may be a plus (or a minus) depending on the situation.

Hope this helps
Philip

_________________
philip


2009-12-08 08:24:33
Profile

Joined: 2009-09-04 13:11:25
Posts: 28
Thank you Phillip.

I'm using a reading method for children that uses colors. I also use this color system with other texts and that is why I have made this macro (which saves me a lot of time even though it is far from perfect).

Pat


2009-12-08 17:58:05
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
I think macros should refer to menu commands as they are in English, no matter what localization you are using. Nisus might then provide a table with English commands and their localized names.

Greetings, Henry.


2009-12-09 07:28:10
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Hi again.
Here is an example of what I meant by trying to write the macro to Nisus' strengths. Instead of searching for each letter one at a time and then doing something, this macro looks at the letters one by one and then applies what is needed.

This macro works by first defining a hash, which associates each letter with a command. It then checks each letter and then carries out the command associated with the letter. I am not sure this is really a better way to do this, but it is another way.

Philip

Code:
# Macro color letters
#
# The following lines set up a hash which defines a command
# to be performed for each letter.
# Further letters can be added as needed.
# Localize is used to allow the macro to work under different system language.
#
$commands = Hash.new
$commands{‘a’} = Localize “Text Color:Red”
$commands{‘e’} = Localize “Text Color:Blue”
$commands{‘i’} = Localize “Text Color:Orange”
$commands{‘o’} = Localize “Text Color:Dark Green”
$commands{‘u’} = Localize “Text Color:Cyan”
#
# The main macro goes through the document text letter by letter.
# If there is a command associated with that letter, it is applied.
#
$doc = Document.active
$text = $doc.text
$len = $text.length
$i = 1
while $i < $len
   $sel = TextSelection.newWithLocationAndLength $text, $i, 1
   $doc.setSelection $sel
   if $commands{$sel.subtext}
      Menu $commands{$sel.subtext}
   end
   $i += 1
end

_________________
philip


2009-12-09 07:39:45
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Groucho wrote:
I think macros should refer to menu commands as they are in English, no matter what localization you are using. Nisus might then provide a table with English commands and their localized names.


Do you means "…should be able to refer to …?"
The ability to refer to menu commands in the local language is just a given. I believe that the Nisus macro feature just passes on the menu command to the user interface. So as long as that command matches something on a menu somewhere then the command is carried out. That is why you can use a user defined macro/style/etc. as a macro command.

As far as being able to use English instead of the localized language, that is possible thanks to the "Localize" command.

What might be a nice idea however might be a sort of global "Localize". Imagine writing "Localize Start/End" before and after a block of menu commands (or at the start of a whole macro) and have it apply to all menu commands in the block (or macro).

_________________
philip


2009-12-09 08:11:11
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
phspaelti wrote:
I believe that the Nisus macro feature just passes on the menu command to the user interface. So as long as that command matches something on a menu somewhere then the command is carried out. That is why you can use a user defined macro/style/etc. as a macro command.

That's exactly correct.
Quote:
As far as being able to use English instead of the localized language, that is possible thanks to the "Localize" command.

Yes and no. The Localize command is very limited in what it can translated. It only translates phrases in the “localizable.strings” file found in the application bundle, which does not hold all menu command names. So while "Bold" is known, something like "Double" which one might want to use for the command Format > Underline > Double is not.

Also, some of the translatable phrases take an unexpected form, eg: instead of finding "Red" one must use "_Red". This last peculiarity should be removed, I'll file it as an issue for fixing, but it's something to be aware of.

Code:
   if $commands{$sel.subtext}
      Menu $commands{$sel.subtext}
   end

One small tip on making this more efficient: since you don't need the formatting, this will be faster:
Code:
   if $commands{$sel.substring}
      Menu $commands{$sel.substring}
   end


2009-12-09 12:24:04
Profile WWW

Joined: 2009-09-04 13:11:25
Posts: 28
It's late and I'm tired but my macro is finally working properly! I would like to thank you all for yours suggestions.

Pat


2009-12-09 22:43:57
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
martin wrote:
Also, some of the translatable phrases take an unexpected form, eg: instead of finding "Red" one must use "_Red". This last peculiarity should be removed, I'll file it as an issue for fixing, but it's something to be aware of.


Indeed, I just had a look a this file. Is there some kind of logic behind why some terms have prefixed "_" ?

martin wrote:
Yes and no. The Localize command is very limited in what it can translated. It only translates phrases in the “localizable.strings” file found in the application bundle, which does not hold all menu command names. So while "Bold" is known, something like "Double" which one might want to use for the command Format > Underline > Double is not.


So how does that work? Is the term "Double" not localized? I see that the file contains "_Double Underline" even though that does not appear on the menu. I guess my question is what this file really represents.

_________________
philip


2009-12-10 00:01:09
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
The "Localizable.strings" file contains phrases that NWP will display to the user. These might be entire sentences, like questions found in prompts, or small phrases used the undo menu or other GUI elements. The words "Double Underline" are used in the stylesheet view, as an attribute bubble. That underscore prefix is just to help us during development; if something appears in the GUI with an underscore, we know it isn't being translated properly.


2009-12-10 15:09:43
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software