Translating the Cardinal Numerals to Words

No problem. I enjoy working with text like this. This level of effort is probably why people suggested you use an existing utility, because it's roughly two pages of code that someone else has already completed. Programmers tend to be lazy, which means they use existing code whenever possible. But I enjoy this sort of task.

EDIT: Okay, it seems to be working fine. However for debugging purposes I had it speak the numbers instead of insert them as text. Now I'm converting it from speaking to typing text, which is a trivial exercise. And I'm prettying up the code to make it look more respectable.

1 Like

Okay, here's the working macro! It's cool! Some notes:

  • If this doesn't meet your needs, I'm certainly happy to change it. The hard part has been done -- any changes that you need are probably no big deal.
  • If you don't pass it any data through its parameter, it creates its own sample data and displays the output for you. It doesn't use the clipboard because that's a dangerous technique.
  • There are two loops: the outer one looks for numbers to work on, and the inner one takes a given number, bunches the digits in groups of three, and processes those groups.
  • I removed commas at the beginning of the macro because you said you wanted to do that.
  • It uses global variables, which is not the best programming practice, but you get what you paid for.
  • People who are curious about how to convert number strings to number-word strings can peruse this macro for ideas.
  • I used awk at one point because when I used only KM macros it added about 100 extra lines that were clear enough, but just too long. So I shortened it with awk.
  • the parts that I coloured in green are the actual workhorse actions, at least conceptually. Take a look at them.

EDIT: I noticed that you might have wanted the string "{cardinal}" and other brackets inserted. If you still do, I can fix that, but check this out first and see if you like it this way.

Cardinals [text] Macro (v10.0.2)

Cardinals [text].kmmacros (25 KB)

1 Like

This looks amazing.

You said it doesn't use the clipboard. How shall I pass the data to the macro then?

You pass data to the macro using the macro's parameter, using a variable like this:

image

Or you could pass it actual data like this:

image

Or if neither of these ways suit you, we can find other ways. I think the first way is best for you. But I can modify the macro if you really need a different way.

Did you try the macro already using its sample data? Were the results satisfactory?

I honestly am not understanding your method. I have tried hard to understand what you are saying: but, no. I am not getting; so frustrated on myself. I am not able to run your macro on my data. whatever I tried, what I always get is your sample data.

What I am used to in processing texts is:
Cut --> process with the macro -->paste or
Cut ---turn the clipboard to variable ---process --set clipboard from variable ---paste

I will get you working, either by showing you how to use variables, or by changing my macro to use the Clipboard instead of a variable. Here's a screenshot of how it should work. I want you to create these actions manually, (for a very good reason that I won't mention) so I'm uploading only a screenshot here:

This sample code will put a copy of the clipboard into a variable and pass that variable into my macro which will the return the result in a global variable called Text.

If I wrote my macro exactly the way you wanted it, and had it work on the clipboard directly, rather than on variables, it would be considered sloppy programming because the clipboard is modifiable by any other macro or by the user. So I wrote it the safer, reliable way. Try this out. I'm sure we'll get you working soon enough.

It is working now. Thank you for explaining; and for being patient with me.

You have also taught me on how to execute a macro on a specific variable (a question I have been asking before).
Really grateful!

How nice. I'm glad you've got it working. If the macro doesn't do something that you want, just ask me for changes.

Where is hundred?

I am testing it on the Ethiopian language by translating the English words:

1256 = αŠ αŠ•α‹΅ αˆΊαˆ… αˆαˆˆα‰΅ Hundred አምሳ αˆ΅α‹΅αˆ΅α‰΅

Magical: it is all fine except the word Hundred

I tried "1256" and it gave me the correct result:

INPUT:
1256
OUTPUT:
One Thousand Two Hundred Fifty Six

Please show me what your input was, rather than your output, because if something is broken I need to see the input so I can fix it.

Yes, it is generating the correct result in English. But, I couldn't find where "hundred" is to translate it to the target language.

Input: 1256
Output: αŠ αŠ•α‹΅ αˆΊαˆ… αˆαˆˆα‰΅ Hundred አምሳ αˆ΅α‹΅αˆ΅α‰΅
Cardinals [text].kmmacros (25.4 KB)

If it translated the number in English correctly, then what are you asking me to do? I don't understand. Do you have another macro that translates into Ethiopian? Is that where the problem is? If you want me to fix your macro, you have to show me your macro.

Oh, you modified my macro to support Ethiopian. Okay, then I can look at it. I didn't know you modified it.

Okay I found the place you missed. It's in there, inside an action that you didn't open by double clicking on it. It looks like this:

Open up that action and see the word "Hundred".

I see. I was expecting it with the other numerals in the green.

Thanks

I guess that was my mistake. I'm not perfect. Glad it's working.

1 Like

it is absolutely amazing macro. I have tried a very large number: worked magically.

If you have time, it would be nice if you can include "hundred" with the other numerals. I think this macro needs to be included in the best Macro list ( Best Macro List - #13) so that others will use it as well.

Unlike the Python and Perl tools listed above, this has the unlimited potential of functioning even for the most obscure languages of the words.
I like the fact that I don't need to request the developer to include this language or that language.

Thanks for the fine compliments.

I'm not sure what that means, above. EDIT: I think I understand what you mean (maybe). You want them all in one place so they are easier to find. I could do that.

Now that I have a better idea of what your were going to do with it, I could have made it a little easier for you by putting all the "words" at the top of the macro for ease of use. But I really didn't know you were going to modify it. That's because I thought you were going to write your own macro to modify my output, rather than modify my macro.

I mean: the Green marked macros are for the user to modify (do the translation). You have four of them.

  • the box that contains the ones
  • the box that contains the tens
  • again the ones
  • finally, the millions

These boxes contain all the text that needs to be translated to a target language. For a new user, it would be hard to find "hundred" barbecue it is not included in these boxes (or its own green box).

I am going to do a translation of your macro for every language I am going to process.