Change resources folder

Hello world,
I would like to use two versions of my program, one in each language, with different images, but with the same names.
The first version would look for the images in English in the resources folder, but the second version would look for the images in Portuguese in the resources_ptbr folder.
How can I change the path of this resources folder in the second version? That way I don’t need to change all the “labels” of the images.

Hey @dimitriusss,

I don’t know if I understand correctly, but I think an option could be to use the add_image method.

Basically, with this method you can add the elements to the image map, passing the path where they are saved.

In the script where you want to use the resources_ptbr folder, you could include the following:

self.add_image("element_1", path="resources_ptbr/element_1.png")
self.add_image("element_2", path="resources_ptbr/element_2.png")
...

# Using the label that was added above
self.find(label="element_1", matching=0.97, waiting_time=10000)
self.find(label="element_2", matching=0.97, waiting_time=10000)

This way, you can use whatever label you want, but pointing to the image that is inside the resources_ptbr folder, and not to the default resources folder.

Hi @joaovoltarelli , first ty for ur reply.

No sorry, this way does not solve the problem. I will try to exemplify better:

We have the home.png image in the resources folder that corresponds to the American house and in the resources_ptbr folder we have the home.png image that corresponds to the Brazilian house.

My code is ready, all referenced for those who use the game in english. Now when starting the program the user can choose whether he is using the game in English or Portuguese.

So that I don’t have to rewrite the code changing the labels from home.png to casa.png, I would like to change the folder. When starting the app, the user will be able to choose whether his game is in English or Portuguese, when doing this option I have to refer the bot to the default resources folder or resources_ptbr.

I hope I explained better

Thx soo much.

in time, I know that I could use:

if not self.find(label=“home”, matching=0.97, waiting_time=10000) or not self.find(label=“casa”, matching=0.97, waiting_time=10000):

but that way i will have to rewrite more than 1000 labels

@dimitriusss, we don’t have a mechanism to change the resource folder exposed via the API.
I opened an issue so we can keep track of that here.

Here are some suggestions on what you can do in the meantime:

  • Use a suffix approach for your labels (e.g.: home-en, home-pt) and just use a formatted string for your label names so they can include the language. You can even do a helper method as to avoid concatenating all the labels with the language suffix.
class Bot(...):
    def action(...):
        self.language = "en"  # change here for your language selection

        if not self.find(label=localize(“home”), matching=0.97, waiting_time=10000):
            ...

    def localize(self, token):
        return f"{token}-{self.language}
1 Like

@dimitriusss we just released a new version of the botcity-framework-base which exposes a new property for the bot to determine the resource folder.

To use it please do the following:

  • Add into your requirements.txt file the following: botcity-framework-base>=0.4.0,<1.0
  • Run pip install --upgrade botcity-framework-base

In your code, simply set the property to the desired folder name:

...
self.resource_folder_name = "resources_ptbr"
...

Let us know if you have any issues using this new feature.

1 Like

Hi, tks for ur solution.

I have already upgraded botcity

Requirement already satisfied: botcity-framework-base in d:\users\pichau\appdata\local\programs\python\python310\lib\site-packages (0.4.2)
Requirement already satisfied: Pillow in d:\users\pichau\appdata\local\programs\python\python310\lib\site-packages (from botcity-framework-base) (9.2.0)
Requirement already satisfied: pyyaml in d:\users\pichau\appdata\local\programs\python\python310\lib\site-packages (from botcity-framework-base) (6.0)

And tried to self.resource_folder_name = “resources_ptbr”
But the code keeps looking at standard folder “resources”