_SPTranslationLanguage field in a CAML query

Antti Mikkonen 96 Reputation points
2023-10-05T16:42:35.2433333+00:00

Is it possible to query list items from the Site pages library using field _SPTranslationLanguage? I would like to get all the pages with English translation. Tried to use this CAML sample:

 		<Eq>
          <FieldRef Name='_SPTranslationLanguage' />
          <Value Type='Choice'>
            en-us
          </Value>
        </Eq>

It seems that field value can be returned in ViewFields but when used in query nothing is returned. I'm using RenderListDataAsStream for querying data.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,844 questions
{count} votes

3 answers

Sort by: Most helpful
  1. ChengFeng - MSFT 5,040 Reputation points Microsoft Vendor
    2023-10-09T07:48:25.6433333+00:00

    Hi @Antti Mikkonen

    The _SPTranslationLanguage field is a multi-valued field that stores all target languages of the page.

    For example, if a page is translated into English and French, the value of this field will be "en-us,fr-fr".

    Therefore, you cannot use the Eq operator to query this field, but should use the Contains operator.

    Please try

    <Contains> <FieldRef Name=‘_SPTranslationLanguage’ /> <Value Type=‘Choice’> en-us </Value> </Contains>
    
    
    

    https://manueltgomes.com/microsoft/sharepoint/translate-your-list-column-names/


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    0 comments No comments

  2. Antti Mikkonen 96 Reputation points
    2023-10-10T09:16:44.3366667+00:00

    Based on my further investigations field _SPTranslationLanguage contains data only on translation pages and the value is current translation's language name. In that case also field _SPIsTranslation is set to true. When the page is created with default language _SPTranslationLanguage is empty and _SPIsTranslation is false. Field _SPTranslatedLanguages on default language page actually contains all the translated languages like you said ChengFeng. Eq operator works fine:

    		<Eq>
              <FieldRef Name="_SPTranslationLanguage" />
              <Value Type="Choice">en-us</Value>
            </Eq>
    

    To use field _SPTranslationLanguage in CAML query must Scope attribute be set in View because all the translated pages are located in document library's subfolders.

    <View Scope="RecursiveAll">
    

    .Antti

    0 comments No comments

  3. ChengFeng - MSFT 5,040 Reputation points Microsoft Vendor
    2023-10-11T02:58:08.7033333+00:00

    Hi @Antti Mikkonen

    I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    [_SPTranslationLanguage field in a CAML query]

    Issue Symptom:

    <Eq>
              <FieldRef Name='_SPTranslationLanguage' />
              <Value Type='Choice'>
                en-us
              </Value>
            </Eq>
    

    It seems that field value can be returned in ViewFields but when used in query nothing is returned.

    Solution:

    To use field _SPTranslationLanguage in CAML query must Scope attribute be set in View because all the translated pages are located in document library's subfolders.

    <View Scope="RecursiveAll">
     
    

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!

    Thank you for your hard work and contribution!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.