Repository: saleor/saleor

Issue:
Add languagecode parameter for quering translated countries available in the shop
### What I'm trying to achieve
I would like to receive translated countries names when using following query:
```
query {
  shop {
    countries {
      country
      code
    }
  }
}
```

With above query I will receive following results:
```
        {
          "country": "Poland",
          "code": "PL"
        },
        {
          "country": "Portugal",
          "code": "PT"
        },
```
### Describe a proposed solution
Add posibility to query for translated country names with for ex. languageCode parameter.

```
query {
  shop {
    countries(languageCode: "PL") {
      country
      code
    }
  }
}
```

Then results from the query will be translated and the response will look like this:

```
        {
          "country": "Polska",
          "code": "PL"
        },
        {
          "country": "Portugalia",
          "code": "PT"
        },
```

###

Django uses `django_countries` package which contains such translations - I guess it should be possible to return translations :)




Discussion:

Resolving patch:
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.py
--- a/saleor/graphql/shop/types.py
+++ b/saleor/graphql/shop/types.py
@@ -1,5 +1,6 @@
 import graphene
 from django.conf import settings
+from django.utils import translation
 from django_countries import countries
 from django_prices_vatlayer.models import VAT
 from phonenumbers import COUNTRY_CODE_TO_REGION_CODE
@@ -71,6 +72,10 @@ class Shop(graphene.ObjectType):
     )
     countries = graphene.List(
         CountryDisplay,
+        language_code=graphene.Argument(
+            LanguageCodeEnum,
+            description="A language code to return the translation for.",
+        ),
         description="List of countries available in the shop.",
         required=True,
     )
@@ -149,14 +154,15 @@ def resolve_authorization_keys(_, _info):
         return site_models.AuthorizationKey.objects.all()
 
     @staticmethod
-    def resolve_countries(_, _info):
+    def resolve_countries(_, _info, language_code=None):
         taxes = {vat.country_code: vat for vat in VAT.objects.all()}
-        return [
-            CountryDisplay(
-                code=country[0], country=country[1], vat=taxes.get(country[0])
-            )
-            for country in countries
-        ]
+        with translation.override(language_code):
+            return [
+                CountryDisplay(
+                    code=country[0], country=country[1], vat=taxes.get(country[0])
+                )
+                for country in countries
+            ]
 
     @staticmethod
     def resolve_currencies(_, _info):


Test patch:
diff --git a/tests/api/test_shop.py b/tests/api/test_shop.py
--- a/tests/api/test_shop.py
+++ b/tests/api/test_shop.py
@@ -1,4 +1,5 @@
 import graphene
+import pytest
 from django_countries import countries
 
 from saleor.core.permissions import MODELS_PERMISSIONS
@@ -30,21 +31,45 @@ def test_query_authorization_keys(
     assert data["authorizationKeys"][0]["key"] == authorization_key.key
 
 
-def test_query_countries(user_api_client):
-    query = """
+COUNTRIES_QUERY = """
     query {
         shop {
-            countries {
+            countries%(attributes)s {
                 code
                 country
             }
         }
     }
-    """
-    response = user_api_client.post_graphql(query)
+"""
+
+
+def test_query_countries(user_api_client):
+    response = user_api_client.post_graphql(COUNTRIES_QUERY % {"attributes": ""})
+    content = get_graphql_content(response)
+    data = content["data"]["shop"]
+    assert len(data["countries"]) == len(countries)
+
+
+@pytest.mark.parametrize(
+    "language_code, expected_value",
+    (
+        ("", "Afghanistan"),
+        ("(languageCode: EN)", "Afghanistan"),
+        ("(languageCode: PL)", "Afganistan"),
+        ("(languageCode: DE)", "Afghanistan"),
+    ),
+)
+def test_query_countries_with_translation(
+    language_code, expected_value, user_api_client
+):
+    response = user_api_client.post_graphql(
+        COUNTRIES_QUERY % {"attributes": language_code}
+    )
     content = get_graphql_content(response)
     data = content["data"]["shop"]
     assert len(data["countries"]) == len(countries)
+    assert data["countries"][0]["code"] == "AF"
+    assert data["countries"][0]["country"] == expected_value
 
 
 def test_query_currencies(user_api_client, settings):