# "Medium" is somehow translate to "Media" even though the locale is default "en\_US" and no .strings file

**URL:** <https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178>\
**Category:** Using Swift\
**Created:** [December 20, 2021, 6:56pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178 "2021-12-20T18:56:19Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [December 20, 2021, 6:56pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/1 "2021-12-20T18:56:19Z")

</div>

```swift
Text("^[\(2) \(String(localized: "Medium"))](inflect: true)") // 2 Media !!! why?

```

Console prints these when run:

```swift
**2021-12-20 10:53:40.144472-0800 LocalizeVooDooWhereMediaFrom[57504:1861217] [Inflection] The word "Medium" is ambiguous. Please annotate your strings file with part of speech info.**

**2021-12-20 10:53:40.145071-0800 LocalizeVooDooWhereMediaFrom[57504:1861217] [Foundation] The word "Medium" is ambiguous. Please annotate your strings file with part of speech info.**

```

I don't understand why "Medium" is translated to "Media". It seems `Foundation` is doing this but I don't understand why this is happening.

```swift
import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("^[\(2) \(String(localized: "Medium"))](inflect: true)") // 2 Media !!! why?
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

```

@Tony_Parker Any idea why?

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [December 20, 2021, 6:59pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/2 "2021-12-20T18:59:13Z")

</div>

“Media” is the plural of “medium” in English, even though people don’t exactly think of it that way most of the time. So this seems to be working correctly.

(This is similar to asking for the plural of “datum” even though “data” can be treated as a mass noun these days, “some data”.)

---

<div class="post-metadata">

**Author:** ![Nevin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nevin/32/617_2.png) [@Nevin](https://forums.swift.org/u/Nevin)\
**Post date:** [December 20, 2021, 7:18pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/3 "2021-12-20T19:18:37Z")

</div>

> [@jrose](#):
>
> “Media” is the plural of “medium” in English

Correction: “media” is _ **a** _ plural of “medium”.

Notably, the definition of “medium” as “an individual held to be a channel of communication between the earthly world and a world of spirits” (Merriam-Webster [definition 2e](https://www.merriam-webster.com/dictionary/medium)) has as its plural exclusively the spelling “mediums”.

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [December 20, 2021, 7:28pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/4 "2021-12-20T19:28:57Z")

</div>

Where is this translation / pluralisation vocabulary stored in the system? I'd like to look at it. What languages it supports? Note, OP doesn't have strings file.

---

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [December 20, 2021, 7:40pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/5 "2021-12-20T19:40:04Z")

</div>

In “WWDC21 What’s New in Foundation”: inflection is supported in English and Spanish.

The feature is called “Automatic Grammar Agreement”. I think it’s computed automatically by Foundation. (I don't think it's simple mapping, it done by some algorithm.)

Edit: At 30:50 "the _ **Automatic Grammar Engine** _ fix up the rest"

---

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [December 20, 2021, 10:16pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/6 "2021-12-20T22:16:46Z")

</div>

```swift
Text("^[\(2) \(String(localized: "forum"))](inflect: true)") // 2 forums

```

What if I want "2 fora" instead of "2 forums"

The console message say:

> Please annotate your strings file with part of speech info.\*\*

There must be some way to tell it to use "mediums" for "medium" (for a person), "fora" for "forums"?

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [December 20, 2021, 11:26pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/7 "2021-12-20T23:26:54Z")

</div>

Is this something customisable via ".stringsdict" file?

PS. "fora" is something 99+% people won't understand as "forums" is the norm.

---

<div class="post-metadata">

**Author:** ![1-877-547-7272](https://avatars.discourse-cdn.com/v4/letter/1/278dde/32.png) [@1-877-547-7272](https://forums.swift.org/u/1-877-547-7272)\
**Post date:** [December 20, 2021, 11:43pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/8 "2021-12-20T23:43:00Z")

</div>

> [@young](#):
>
> The console message say:
> 
> > Please annotate your strings file with part of speech info.\*\*

According to [this sample project](https://developer.apple.com/documentation/foundation/data_formatting/building_a_localized_food-ordering_app):

> In some languages, an app may need to provide part-of-speech information to the inflection engine. This happens in English, where the words “sandwich” and “juice” are both a noun and a verb. In Spanish, the food size terms “grande” and “enorme” can be used as both adjectives and nouns. The inflection engine logs a warning when it encounters this type of ambiguity. To clarify intent, the inflection engine accepts a grammar markup that wraps the substitution with the syntax `^[…](morphology: {…})` and provides part-of-speech information. The following entry from the English strings file shows an example of this disambiguation:
> 
> ```swift
> "Add ^[%lld %@ %@](inflect: true) to your order" = "Add ^[%lld %@ ^[%@](morphology: { partOfSpeech: \"noun\" })](inflect: true) to your order";
> 
> ```

---

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [December 21, 2021, 12:22am UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/9 "2021-12-21T00:22:43Z")

</div>

> [@tera](#):
>
> PS. "fora" is something 99+% people won't understand as "forums" is the norm

I'm just using this as an example to ask how to force inflection to use equally valid alternative spelling.

There is `inflectionAlternative` value you can provide:

```swift
Text("^[\(2) \(String(localized: "Cactus"))](inflect: true, inflectionAlternative: 'Cactuses')") // 2 Cacti

```

It's still `Cati`. I need to go watch the presentation to see what it does.

Edit: `inflectionAlternative` is for when "term of address (Feminine, Masculine or Neuter setting is unknown, not for pluralization)

---

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [December 21, 2021, 12:32am UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/10 "2021-12-21T00:32:30Z")

</div>

Aha! `Morphology`, there is so much going on with this:

```swift
public enum InflectionRule {

    case automatic

    case explicit(Morphology)

    public init(morphology: Morphology)
}

```

`Morphology` has: `GrammaticalGender`, `PartOfSpeech`, `GrammaticalNumber` 🤔

Maybe Morphology `GrammaticalNumber` is how to tell it to use which plural spelling?

> [@1-877-547-7272](#):
>
> `morphology: { partOfSpeech: \"noun\" }`

Here is how to ad-hoc specify this in source code:

```swift
Text("^[\(2) ^[\(String(localized: "medium"))](morphology: { partOfSpeech: \"noun\" })](inflect: true)") // 2 media b/c automatic grammar agreement

```

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [December 29, 2021, 4:05pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/11 "2021-12-29T16:05:34Z")

</div>

from the sample code:

> [@](#):
>
> For example, one small salad becomes "1 ensalada pequeña" in Spanish, while two small salads is "2 ensaladas pequeñas". In both cases, the grammar engine changes the adjective "pequeño" to match the feminine gender of "ensalada".

Interestingly it doesn't change "pequeño" to "pequeña" for "ensalada". Although it changes from "1 ensalada pequeño" to "2 ensaladas pequeños". Bug? Tested with Xcode 13.2.1, iOS 15.2.

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [December 29, 2021, 10:27pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/12 "2021-12-29T22:27:37Z")

</div>

Don't know why that sample code didn't work as advertised out of the box, but I managed to get a minimal sample app working as intended:

```
struct ContentView: View {
    var body: some View {
        let word = "ensalada"
        let small = String(localized: "small")
        let locKey: LocalizedStringKey = "^[\(word) \(small)](inflect: true)"
        let locString = String(localized: "^[\(word) \(small)](inflect: true)")
        
        VStack {
            Text(locKey)
            Text(locString)
        }
    }
}

```

with this in the Spanish localizable strings file:

```
"small" = "pequeño";

```

This correctly shows `ensalada pequeña` on screen, changing `pequeño` appropriately to match feminine `ensalada`. As for the second string (locString) it shows this: `^[ensalada pequeño](inflect: true)` which is not exactly what I was hoping for: I was after the string `ensalada pequeña` as it is shown in UI. How do I get that string? The idea is to see the resulting string containing "pequeño" / pequeña / "pequeños" as a round about way of getting word's gender (I don't see string's gender directly available in the API).

---

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [December 29, 2021, 10:36pm UTC](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/13 "2021-12-29T22:36:16Z")

</div>

`Morphology` has a [`GrammaticalGender`](https://forums.swift.org/t/medium-is-somehow-translate-to-media-even-though-the-locale-is-default-en-us-and-no-strings-file/54178/10) enum plus two other enum's. I don't know how it's supposed to be used, whether it can be specified in the inflection json expression, or could it be used only by the OS to indicate the ueer's "Term of Address"?

I wish to know if this "Automatic Grammar Engine" can be control so that we can tell it e.g. "Medium" is a person, not a size so it should pluralize it as "Mediums", not "Media" as @Nevin said above.
