LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the most optimized solution? Software Translation/Translation Dictionary

Solved!
Go to solution

Hello

I have the following translation system in my application:

I have a txt file with a tag + a tab + the translation
And so there are countless lines (currently, more than 8 thousand lines)

Every time the software needs to translate a field, it reads the file, looks up the tag, and picks up the translation

I have the following idea:
When you open the software, it reads the txt and saves it in a global variable (array) and every time it needs to translate it reads from the global variable

What is the most optimal option?

0 Kudos
Message 1 of 11
(283 Views)

Change "array" to "Map" and it's all good. 🙂

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 11
(282 Views)
Solution
Accepted by topic author leandrofeder

Yamaeda_0-1727444761370.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 11
(279 Views)

But what would it look like so that I can use it in all my code?

Imagining in the scenario that I have numerous VIs that consume the translation

Wouldn't it have to save in a global variable at the beginning of the software?

Would it be a global variable of the Map type? Right?

I'm asking because I have not yet used this method

0 Kudos
Message 4 of 11
(274 Views)

Yes, it must be global or kind of, so you only read the file once.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 11
(253 Views)

@leandrofeder wrote:

But what would it look like so that I can use it in all my code?

Imagining in the scenario that I have numerous VIs that consume the translation

Wouldn't it have to save in a global variable at the beginning of the software?

Would it be a global variable of the Map type? Right?

I'm asking because I have not yet used this method


You can do it more than one way. The traditional way (FGV with the function being translate): 

 

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000015BjzSAE&l=en-US

 

Or the OOP way with a dictionary class with translate methods ( this one is a bit harder if you don't have any OOP experience 😞 

 

https://www.ni.com/en/support/documentation/supplemental/06/labview-object-oriented-programming--the...

 

Or the ACTOR way with a translation layer in messaging ( this one is harder still to implement correctly ) 

 

https://labviewwiki.org/wiki/Actor_Framework_is_not_as_hard_as_you_think_and_here_is_why%E2%80%A6

 

 

Probably start with the FGV : ) 

 

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 6 of 11
(247 Views)

@Yamaeda wrote:

Yamaeda_0-1727444761370.png

 


I would go with this approach as well, converted into a FGV or action engine, dictionaries i.e., maps in LabVIEW fit well for your use case.

Are you sure, there will not be any duplicates in the tags?

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 7 of 11
(220 Views)

Definitely go with an action engine. It doesn't sound like your map is too terribly big, and it sounds like you would use it infrequently, but I've had performance issues in the past when I passed a large map around to different parts of my code. There were apparently some memory duplication issues going on and the map was getting copied a few times. This slowed things down a LOT.

 

I switched to passing around a DVR that contained the map. This made my code a million times faster. An Action Engine would work the same way- you just have the one copy of the map.

 

A global variable of type Map could very likely wind up duplicating the map each time you use it and look up a value. You could try to use some in-place structures to mitigate things, but an action engine would make it a lot simpler.

 

(In my case it was likely some sort of combo of dynamic dispatching, cloned VI's, etc that made the map get copied. I never wrote anything TO the map, and only used the "Look in map" function, but the compiler couldn't figure out how to keep a single copy and it really slowed things down.)

 

One other completely separate approach- you could use an SQLite database and read from that. This could make things a little easier if you need to switch between multiple languages. This library is very easy to use: https://www.ni.com/en/support/downloads/tools-network/download.sqlite-library.html#374489

 

I'd still make a wrapper around it so you don't have to have SQL on your block diagrams, but it would be quite simple to use.

Message 8 of 11
(217 Views)

In my case, where do I enter with the tag in VI and need the result?
Why would it be unfeasible to create 8 thousand tags/lines, right?

 

Or did I get it wrong? Would I have to create an action for each tag?

leandrofeder_1-1727455587397.png

 



leandrofeder_0-1727455146175.png

 

0 Kudos
Message 9 of 11
(188 Views)

No, you'll want to load all of the values into a Map, then use "Look in Map". That function accepts a "key" as its input and returns the associated "value" as its output.

 

Your case structure will just be the actions- "initialize" and "get key" would be the only two states you'd need, unless you had other bookkeeping to do.

Message 10 of 11
(173 Views)