Nextcloud call function to get Language Code in app

Hi, sorry for such a basic question. I am new to nextcloud app development, so I used the sample structure generated by the nextcloud app and uploaded it onto my nextcloud server for testing.
I am trying to get the language code within the nextcloud using the following code :

In my App.vue

async language() {
        this.updatingType = true
        try {
            const response = await axios.get(OC.generateUrl(`/apps/myApp/types/languageCode`))
            OCP.Toast.error(t('myApp', 'Language Code'))
            OCP.Toast.error(t('myApp', response.data))
        } catch (e) {
            console.error(e)
            OCP.Toast.error(t('myApp', 'Could not get language'))
        }
        this.updatingType = false
    }, 

In the controller, I am calling the function as such:

    use \OCP\IL10N;
    class {
           private $l;

           public function __construct(Class $class, IL10N $l) {
                 $this->class = $class;
                 $this->l = $l;
           }


           public function getLanguageCode() {
           return $this->l->getLanguageCode();
       }
   }

But when calling the function from App.vue it is giving me the error pop up

‘Language not Found’

can anyone please help me out a little, what I am doing wrong and how can I get the current language code of nextcloud ?
Thank you

From your shared code I cannot see where the ‘Language not Found’ should be coming from. For getting the code inside of your Vue component you could also just use our @nextcloud/l10n npm package which comes with a getLanguage function:

https://nextcloud.github.io/nextcloud-l10n/globals.html#getlanguage

Thank you @juliushaertl , I got the response using the

@nextcloud/l10n’

package, the function I made is like this :

 async language() {
        this.updatingType = true
        try {
            /** const response = await axios.post(OC.generateUrl(`/apps/organization/types/lang/1`)) */
            const response = await OC.getLanguage()
            OCP.Toast.error(t('organization', 'Language Code'))
            OCP.Toast.error(t('organization', response.data))
            OCP.Toast.error(t('organization', response))
        } catch (e) {
            console.error(e)
            OCP.Toast.error(t('organization', 'Could not get language'))
        }
        this.updatingType = false
    },

This solved my issue as response is giving me the language code, thank you.

getLanguage is just returning a string, not a promise so no need to await this, so instead try the following:

import { getLanguage } from '@nextcloud/l10n'

...
    language() {
        this.updatingType = true
        const language = getLanguage()
        // do whatever you need the language for
        this.updatingType = false
    },

Note that this is the deprecated global variable. The proper replacement is decribed in my previous post, to use the one from the l10n package.

Thank you, will change to the new one.

@juliushaertl… Can you please also guide me how I can get access to user list for showing inside my application. I checked on vue components but could not find one for user management and my custom controller for registration database table is not getting any value.
Thank you.