Skip to main content

I’d like to get current user’s country, so I can show my plugin with the appropriate system language, and I tried several approaches:




  1. HTML Geolocation API

    Figma plugin’s origin is set to *, so I can’t use navigator.geolocation.getCurrentPosition() inside Figma plugin.




  2. Geolocation by IP address

    This works, but the downside is that, this is an asynchronous method, which can cause a fraction of a change when the React rendering the page with given language context.




So is there any solution for this ?


Thanks.

Using a country to determine user’s language is a bad idea in the first place (and I don’t think there is an api for that). Imagine you are traveling to another country or simply using a VPN — you won’t be able to read anything. A much better way is to use the user’s locale. I think it should be available.



@Gleb figma doesn’t support the navigator object so there is no way to directly access the users preferred language 😞


Correction: you can access the users language!

You will need something like this in your ui.html:


parent.postMessage({ pluginMessage: { navigator.language} }, '*')

and then this in your code.ts


figma.ui.onmessage = msg => {
msg; // do whatever you need with the language here
}

Reply