https://discord.umbraco.com logo
#help-with-umbraco
Get CMS Culture
# help-with-umbraco
y

yaseinburqan

01/28/2024, 12:47 PM
How can I Get CMS Culture by code? I want to get the current language that is the user work in by C# like : if user work on English get English if user work on French get French ...etc ?
r

Rachel D

01/28/2024, 1:56 PM
I believe you can retrieve what culture (and therefore language) is being used in a template via
CultureInfo.CurrentUICulture
, which is in the
System.Globalization
namespace in C#
y

yaseinburqan

01/28/2024, 3:35 PM
@Rachel D What I am trying to do is retrieve what culture that is the current user work on , but not in the template
j

jespermayntzhusen

01/29/2024, 8:13 AM
If you have domains specified with cultures on the root level, and have a node context then you can do node.GetCultureFromDomains()
y

yaseinburqan

01/29/2024, 10:14 AM
Hi @jespermayntzhusen , I did not got it , Could you provide me some sources?
j

jespermayntzhusen

01/29/2024, 10:18 AM
Think you need to provide more context about what you are trying to do, and from within what kind of code you are doing it
y

yaseinburqan

01/29/2024, 10:43 AM
@jespermayntzhusen I am trying to call an API , I create a custom property that call API and fetch the data , so what I am trying is fitch the data by the culture, the proerety take the api so if I provide the language in the API it will be for all the same data, for that I want to catch the current language for the cms to edit on the api and call by the language
j

jespermayntzhusen

01/29/2024, 11:10 AM
Ahh ok, if it is from within the context of a custom property editor, then you can get it from the route, for multilingual content the culture of the content you are currently working on is added in the url via the mculture param. You can inject $routeParams into the controller and then call
$routeParams.mculture
But be aware that for split view editing there is currently no way of knowing which of the 2 you are calling your editor from - can't remember if the mculture param is from the initial or the newly opened split view version of the node