OfficeDev / office-js-docs

[ARCHIVED] Microsoft Office Add-ins API Reference Documentation
https://docs.microsoft.com/javascript/api/overview/office
398 stars 247 forks source link

Office.context.contentLanguage does not respect Office host app's selected language #1451

Closed georgechr closed 6 years ago

georgechr commented 6 years ago

According to the documentation Office.context.contentLanguage should get the locale as specified in the Office host application. Instead, it seems to always return 'en-US' no matter what the editing language is set as. The same issue appears for displayLanguage as well.

Article URL

https://dev.office.com/reference/add-ins/shared/office.context.contentlanguage

Rick-Kirkham commented 6 years ago

I'm not able to reproduce this. What version of Office are you on?

georgechr commented 6 years ago

@Rick-Kirkham thanks for your reply. I am on Excel 2016 16.0.7726.1059

Below are the screenshots from the debugger and actual selected content language

debugger default

Rick-Kirkham commented 6 years ago
  1. Try a non-English language, like French, just to see what happens.
  2. Can you provide a complete Word.run() that I can use in Script Lab?
georgechr commented 6 years ago
  1. I have, same results. Office.context.contentLanguage still prints "en-US"

  2. The issue happens in Excel, not Word. Nevertheless, the content language is not part of the Excel API and can be accessed synchronously so just printing Office.context.contentLanguage should work.

georgechr commented 6 years ago

So, is this an actual issue? Should we come up with a workaround until is fixed? It is causing issues when our add-ins are sorting and then displaying dates in Excel worksheets (half of them on average - the ones that can get parsed as US dates - are displayed wrong)

Rick-Kirkham commented 6 years ago

@georgechr I've been on vacation. If you're still experiencing this issue could you provide me with a complete Excel.run? Just enough to illustrate the issue. I cannot reproduce this error with my own code.

georgechr commented 6 years ago

This reproduces it for me i.e. it always prints 'en-US' in the selected cell.

Excel.run((context) => {
  const range = context.workbook.getSelectedRange();
  range.values = [[Office.context.contentLanguage]];
  await context.sync();
}).catch(function(_) {
})
Rick-Kirkham commented 6 years ago

Your code works perfectly for me. I get en-GB when I switch to English United Kingdom. You do have to close Excel and reopen it for the change to take effect. I'm on subscription Office (Click-to-Run). You are on Office 2016 MSI. This looks like a bug, so please raise the issue on the repo office-js. Be sure to specify your Excel version.

At any rate, its not a documentation problem, and that's what the issues for this repo are intended to track, so I'm going to have to close this here.