diff --git a/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php b/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php
index 7e7b732..5c7753f 100644
--- a/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php
@@ -8,14 +8,15 @@
 namespace Drupal\address\Plugin\Field\FieldFormatter;
 
 use CommerceGuys\Addressing\Enum\AddressField;
-use CommerceGuys\Addressing\Model\AddressInterface;
 use CommerceGuys\Addressing\Repository\AddressFormatRepositoryInterface;
 use CommerceGuys\Addressing\Repository\CountryRepositoryInterface;
 use CommerceGuys\Addressing\Repository\SubdivisionRepositoryInterface;
-use Drupal\address\FieldHelper;
+use Drupal\address\AddressInterface;
+use Drupal\address\Entity\AddressFormatInterface;
 use Drupal\Core\Field\FormatterBase;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use Drupal\Core\Render\Element;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -38,7 +39,7 @@ class AddressPlainFormatter extends FormatterBase implements ContainerFactoryPlu
    *
    * @var \CommerceGuys\Addressing\Repository\AddressFormatRepositoryInterface
    */
-  protected $addressFormatRepository;
+  protected $address_formatRepository;
 
   /**
    * The country repository.
@@ -108,41 +109,66 @@ class AddressPlainFormatter extends FormatterBase implements ContainerFactoryPlu
   /**
    * {@inheritdoc}
    */
-  public function viewElements(FieldItemListInterface $items) {
+  public function viewElements(FieldItemListInterface $items, $langcode) {
     $elements = [];
     foreach ($items as $delta => $item) {
-      $countryCode = $item->getCountryCode();
-      $countries = $this->countryRepository->getList();
-      $country = $countries[$countryCode];
-      $values = $this->getSubdivisions($item);
-      $elements[$delta] = [
-        '#theme' => 'address_plain',
-        '#recipient' => $values['recipient'],
-        '#organization' => $values['organization'],
-        '#address_line1' => $values['addressLine1'],
-        '#address_line2' => $values['addressLine2'],
-        '#postal_code' => $values['postalCode'],
-        '#sorting_code' => $values['sortingCode'],
-        '#administrative_area' => $values['administrativeArea'],
-        '#locality' => $values['locality'],
-        '#dependent_locality' => $values['dependentLocality'],
-        '#country' => ['code' => $countryCode, 'name' => $country],
-      ];
+      $elements[$delta] = $this->viewElement($item, $langcode);
     }
 
     return $elements;
   }
 
   /**
-   * Gets the subdivisiona.
+   * Builds a renderable array for a single address item.
    *
-   * @param \CommerceGuys\Addressing\Model\AddressInterface $address
+   * @param \Drupal\address\AddressInterface $address
    *   The address.
+   * @param string $langcode
+   *   The language that should be used to render the field.
    *
    * @return array
-   *   The values, keyed by theme's subdivision name.
+   *   A renderable array.
    */
-  protected function getSubdivisions(AddressInterface $address) {
+  protected function viewElement(AddressInterface $address, $langcode) {
+    $country_code = $address->getCountryCode();
+    $countries = $this->countryRepository->getList();
+    $address_format = $this->addressFormatRepository->get($country_code, $address->getLocale());
+    $values = $this->getValues($address, $address_format);
+
+    $element = [
+      '#theme' => 'address_plain',
+      '#recipient' => $values['recipient'],
+      '#organization' => $values['organization'],
+      '#address_line1' => $values['addressLine1'],
+      '#address_line2' => $values['addressLine2'],
+      '#postal_code' => $values['postalCode'],
+      '#sorting_code' => $values['sortingCode'],
+      '#administrative_area' => $values['administrativeArea'],
+      '#locality' => $values['locality'],
+      '#dependent_locality' => $values['dependentLocality'],
+      '#country' => ['code' => $country_code, 'name' => $countries[$country_code]],
+      '#cache' => [
+        'contexts' => [
+          'languages:' . LanguageInterface::TYPE_INTERFACE,
+        ],
+      ],
+    ];
+
+    return $element;
+  }
+
+  /**
+   * Gets the address values used for rendering.
+   *
+   * @param \Drupal\address\AddressInterface $address
+   *   The address.
+   * @param \Drupal\address\Entity\AddressFormatInterface $address_format
+   *   The address format.
+   *
+   * @return array
+   *   The values, keyed by address field.
+   */
+  protected function getValues(AddressInterface $address, AddressFormatInterface $address_format) {
     $values = [];
     foreach (AddressField::getAll() as $field) {
       $getter = 'get' . ucfirst($field);
@@ -150,12 +176,7 @@ class AddressPlainFormatter extends FormatterBase implements ContainerFactoryPlu
     }
 
     // Replace the subdivision values with the names of any predefined ones.
-    $subdivisionFields = [
-      AddressField::ADMINISTRATIVE_AREA,
-      AddressField::LOCALITY,
-      AddressField::DEPENDENT_LOCALITY,
-    ];
-    foreach ($subdivisionFields as $field) {
+    foreach ($address_format->getUsedSubdivisionFields() as $field) {
       if (empty($values[$field])) {
         // This level is empty, so there can be no sublevels.
         break;
@@ -173,13 +194,6 @@ class AddressPlainFormatter extends FormatterBase implements ContainerFactoryPlu
       }
     }
 
-    // If there were no corresponding objects found, load strings from $address.
-    foreach ($subdivisionFields as $field) {
-      $getter = 'get' . ucfirst($field);
-      if (!isset($values[$field]) || !is_array($values[$field])) {
-        $values[$field] = ['code' => '', 'name' => $address->$getter()];
-      }
-    }
     return $values;
   }
 
diff --git a/src/Plugin/Field/FieldType/AddressItem.php b/src/Plugin/Field/FieldType/AddressItem.php
index 8c898fa..0afbffc 100644
--- a/src/Plugin/Field/FieldType/AddressItem.php
+++ b/src/Plugin/Field/FieldType/AddressItem.php
@@ -97,7 +97,7 @@ class AddressItem extends FieldItemBase implements AddressInterface {
    */
   public static function propertyDefinitions(FieldStorageDefinitionInterface $fieldDefinition) {
     $properties = [];
-    $properties['langcode'] = DataDefinition::create('language')
+    $properties['langcode'] = DataDefinition::create('string')
       ->setLabel(t('The language code.'));
     $properties['country_code'] = DataDefinition::create('string')
       ->setLabel(t('The two-letter country code.'));
diff --git a/src/Tests/Formatter/PlainFormatterTest.php b/src/Tests/Formatter/PlainFormatterTest.php
index 52a026f..918e1c5 100644
--- a/src/Tests/Formatter/PlainFormatterTest.php
+++ b/src/Tests/Formatter/PlainFormatterTest.php
@@ -7,31 +7,34 @@
 
 namespace Drupal\address\Tests\Formatter;
 
-use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\entity_test\Entity\EntityTest;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Entity\FieldStorageConfig;
-use Drupal\simpletest\KernelTestBase;
 use Drupal\language\Entity\ConfigurableLanguage;
-use CommerceGuys\Addressing\Enum\AddressField;
-use CommerceGuys\Addressing\Model\Address;
-use CommerceGuys\Addressing\Repository\CountryRepository;
-use CommerceGuys\Addressing\Repository\SubdivisionRepository;
+use Drupal\simpletest\KernelTestBase;
+
 /**
- * @coversDefaultClass \CommerceGuys\Addressing\Formatter\PlainFormatter
+ * Tests the plain formatter.
  *
  * @group address
- *
  */
 class PlainFormatterTest extends KernelTestBase {
 
   /**
-   * {@inheritdoc}
+   * @var array
    */
-  public static $modules = ['system', 'language', 'field', 'text', 'entity_test', 'user', 'address'];
+  public static $modules = [
+    'system',
+    'field',
+    'language',
+    'text',
+    'entity_test',
+    'user',
+    'address'
+  ];
 
   /**
    * @var string
@@ -54,37 +57,25 @@ class PlainFormatterTest extends KernelTestBase {
   protected $display;
 
   /**
-   * @var string
-   */
-  protected $storage;
-
-  /**
-   * The country repository.
-   *
-   * @var CountryRepositoryInterface
-   */
-  protected $countryRepository;
-  /**
-   * The subdivision repository.
-   *
-   * @var SubdivisionRepositoryInterface
-   */
-  protected $subdivisionRepository;
-  
-  /**
    * {@inheritdoc}
    */
   protected function setUp() {
     parent::setUp();
 
-    $this->enableModules(array('address'));
     $this->installConfig(['system']);
-    $this->installConfig(['language']);
     $this->installConfig(['field']);
     $this->installConfig(['text']);
     $this->installConfig(['address']);
     $this->installEntitySchema('entity_test');
-    $this->installEntitySchema('address_format');
+
+    ConfigurableLanguage::createFromLangcode('zh-hant')->save();
+
+    // The address module is never installed, so the importer doesn't run
+    // automatically. Instead, we manually import the address formats we need.
+    $country_codes = ['AD', 'SV', 'TW', 'US', 'ZZ'];
+    $importer = \Drupal::service('address.address_format_importer');
+    $importer->importEntities($country_codes);
+    $importer->importTranslations(['zh-hant']);
 
     $this->entityType = 'entity_test';
     $this->bundle = $this->entityType;
@@ -97,247 +88,147 @@ class PlainFormatterTest extends KernelTestBase {
     ]);
     $field_storage->save();
 
-    $instance = FieldConfig::create([
+    $field = FieldConfig::create([
       'field_storage' => $field_storage,
       'bundle' => $this->bundle,
       'label' => $this->randomMachineName(),
     ]);
-    $instance->save();
+    $field->save();
 
     $this->display = entity_get_display($this->entityType, $this->bundle, 'default');
-    $component = $this->display->getComponent($this->fieldName);
-    $component['type'] = 'address_plain';
-    $this->display->setComponent($this->fieldName, $component);
+    $this->display->setComponent($this->fieldName, [
+      'type' => 'address_plain',
+      'settings' => [],
+    ]);
     $this->display->save();
-    
-    $this->countryRepository = new CountryRepository();
-    $this->subdivisionRepository = new SubdivisionRepository();
   }
+
   /**
-   * Tests El Salvador mocking address.
+   * Tests Andorra address formatting.
    */
-  public function testElSalvadorAddress()
-  {
-    // Mocking values.
-    $countryCode = 'SV';
-    $administrativeArea = 'SV-AH';
-    $locality = 'Ahuachapán';
-    $addressLine1 = 'Some Street 12';
-    $postalCode = 'CP 2101';
-    $recipient = 'Some Recipient';
-    
-    // Create the address object
-    $address = new Address();
-    $address
-      ->setCountryCode($countryCode)
-      ->setAdministrativeArea($administrativeArea)
-      ->setLocality($locality)
-      ->setAddressLine1($addressLine1)
-      ->setPostalCode($postalCode)
-      ->setRecipient($recipient);
-
-    // Create the entity object
+  public function testAndorraAddress() {
     $entity = EntityTest::create([]);
-    $entity->set($this->fieldName, [
-      'country_code' => $countryCode,
-      'administrative_area' => $administrativeArea,
-      'locality' => $locality,
-      'address_line1' => $addressLine1,
-      'postal_code' => $postalCode,
-      'recipient' => $recipient,
+    $entity->{$this->fieldName} = [
+      'country_code' => 'AD',
+      'locality' => 'AD-07',
+      'postal_code' => 'AD500',
+      'address_line1' => 'C. Prat de la Creu, 62-64',
+    ];
+    $this->renderEntityFields($entity, $this->display);
+
+    $expected = implode("\n", [
+      'line1' => '',
+      'line2' => '',
+      'line3' => 'C. Prat de la Creu, 62-64',
+      'line4' => '',
+      'line5' => '',
+      'line6' => 'Parròquia d&#039;Andorra la Vella',
+      'line7' => 'AD500',
+      'line8' => 'Andorra la Vella',
+      'line9' => '',
+      'line10' => 'Andorra',
     ]);
-
-    // Render the entity
-    $this->renderEntityFields($entity);
-    $this->assertRaw($this->getExpectedString($address));
+    $this->assertRaw($expected);
   }
+
   /**
    * Tests Taiwan mocking address.
    */
-  public function testTaiwanAddress()
-  {
-    // Real addresses in the major-to-minor order would be completely in
-    // Traditional Chinese. That's not the case here, for readability.
-    // Mocking values.
-    $locale = 'zh-hant';
-    $countryCode = 'TW';
-    $administrativeArea = 'TW-TPE';
-    $locality = 'TW-TPE-e3cc33';
-    $addressLine1 = 'Sec. 3 Hsin-yi Rd.';
-    $postalCode = '100';
-    $organization = 'Giant Bike Store';
-    $recipient = 'Mr. Liu';
-    
-    // Create the address object    
-    $address = new Address();
-    $address
-      ->setLocale($locale)
-      ->setCountryCode($countryCode)
-      ->setAdministrativeArea($administrativeArea)  // Taipei city
-      ->setLocality($locality)  // Da-an district
-      ->setAddressLine1($addressLine1)
-      ->setPostalCode($postalCode)
-      ->setOrganization($organization)
-      ->setRecipient($recipient);    
+  public function testTaiwanAddress() {
+    $language = \Drupal::languageManager()->getLanguage('zh-hant');
+    \Drupal::languageManager()->setConfigOverrideLanguage($language);
 
-    // Create the entity object
-    ConfigurableLanguage::createFromLangcode($locale)->save();
     $entity = EntityTest::create([]);
-    $entity->addTranslation($locale)->set($this->fieldName, [
-      'country_code' => $countryCode,
-      'administrative_area' => $administrativeArea,
-      'locality' => $locality,
-      'address_line1' => $addressLine1,
-      'postal_code' => $postalCode,
-      'recipient' => $recipient,
-      'organization' => $organization,
+    $entity->{$this->fieldName} = [
+      'langcode' => 'zh-hant',
+      'country_code' => 'TW',
+      'administrative_area' => 'TW-TPE',
+      'locality' => 'TW-TPE-e3cc33',
+      'address_line1' => 'Sec. 3 Hsin-yi Rd.',
+      'postal_code' => '106',
+      // Any HTML in the fields is supposed to be escaped.
+      'organization' => 'Giant <h2>Bike</h2> Store',
+      'recipient' => 'Mr. Liu',
+    ];
+    $this->renderEntityFields($entity, $this->display);
+
+    $expected = implode("\n", [
+      'line1' => 'Mr. Liu',
+      'line2' => 'Giant &lt;h2&gt;Bike&lt;/h2&gt; Store',
+      'line3' => 'Sec. 3 Hsin-yi Rd.',
+      'line4' => '',
+      'line5' => '',
+      'line6' => '大安區',
+      'line7' => '106',
+      'line8' => '大安區',
+      'line9' => '台北市',
+      'line10' => '台灣',
     ]);
-
-    // Render the entity
-    $this->renderEntityFields($entity->getTranslation($locale));
-    $this->assertRaw($this->getExpectedString($address));
+    $this->assertRaw($expected);
   }
+
   /**
    * Tests US mocking address.
    */
-  public function testUnitedStatesIncompleteAddress()
-  {
-    // Mocking values.
-    $countryCode = 'US';
-    $administrativeArea = 'US-CA';
-    $addressLine1 = '1098 Alta Ave';
-    $postalCode = '94043';
-    $locality = 'Mountain View';
-
-    // Create a US address without a locality.
-    $address = new Address();
-    $address
-      ->setAdministrativeArea($administrativeArea)
-      ->setCountryCode($countryCode)
-      ->setAddressLine1($addressLine1)
-      ->setPostalCode($postalCode);
-      
-    // Create the entity object
+  public function testUnitedStatesIncompleteAddress() {
     $entity = EntityTest::create([]);
-    $entity->set($this->fieldName, [
-      'country_code' => $countryCode,
-      'administrative_area' => $administrativeArea,
-      'address_line1' => $addressLine1,
-      'postal_code' => $postalCode,
+    $entity->{$this->fieldName} = [
+      'country_code' => 'US',
+      'administrative_area' => 'US-CA',
+      'address_line1' => '1098 Alta Ave',
+      'postal_code' => '94043',
+    ];
+    $this->renderEntityFields($entity, $this->display);
+
+    $expected = implode("\n", [
+      'line1' => '',
+      'line2' => '',
+      'line3' => '1098 Alta Ave',
+      'line4' => '',
+      'line5' => '',
+      'line6' => '',
+      'line7' => '94043',
+      'line8' => '',
+      'line9' => 'CA',
+      'line10' => 'United States',
     ]);
-    // Render the entity
-    $this->renderEntityFields($entity);
-    $this->assertRaw($this->getExpectedString($address));
+    $this->assertRaw($expected);
 
     // Now add the locality, but remove the administrative area.
-    $address
-      ->setLocality($locality)
-      ->setAdministrativeArea('');
-    $entity->set($this->fieldName, [
-      'country_code' => $countryCode,
-      'administrative_area' => '',
-      'address_line1' => $addressLine1,
-      'postal_code' => $postalCode,
-      'locality' => $locality,
+    $entity->{$this->fieldName}->locality = 'Mountain View';
+    $entity->{$this->fieldName}->administrative_area = '';
+    $this->renderEntityFields($entity, $this->display);
+
+    $expected = implode("\n", [
+      'line1' => '',
+      'line2' => '',
+      'line3' => '1098 Alta Ave',
+      'line4' => '',
+      'line5' => '',
+      'line6' => '',
+      'line7' => '94043',
+      'line8' => 'Mountain View',
+      'line9' => '',
+      'line10' => 'United States',
     ]);
-    // Render the entity
-    $this->renderEntityFields($entity);
-    $this->assertRaw($this->getExpectedString($address));
+    $this->assertRaw($expected);
   }
+
   /**
-   * Renders address fields with a given display.
+   * Renders fields of a given entity with a given display.
    *
    * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
    *   The entity object with attached fields to render.
+   * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
+   *   The display to render the fields in.
    *
    * @return string
    *   The rendered entity fields.
    */
-  protected function renderEntityFields(FieldableEntityInterface $entity) {
-    $content = $this->display->build($entity);
+  protected function renderEntityFields(FieldableEntityInterface $entity, EntityViewDisplayInterface $display) {
+    $content = $display->build($entity);
     $content = $this->render($content);
     return $content;
   }
-  /**
-   * Returns expected string from the plain template.
-   *
-   * @param \CommerceGuys\Addressing\Model\Address $address
-   *   The address.
-   *
-   * @return string
-   *   The expected string.
-   */
-  protected function getExpectedString(Address $address) {
-    // Get country
-    $countries = $this->countryRepository->getList();  
-    $country = $countries[$address->getCountryCode()];
-    // Get subdivisions
-    $values = $this->getSubdivisions($address);
-    
-    // Format the expected value from $address object
-    $expected = SafeMarkup::format("@line1\n@line2\n@line3\n@line4\n@line5\n@line6\n@line7", [
-      '@line1' => $values['recipient'],
-      '@line2' => $values['organization'],
-      '@line3' => $values['addressLine1'],
-      '@line4' => $values['addressLine2'],
-      '@line5' => $values['dependentLocality']['code'],
-      '@line6' => $values['locality']['code'] .' '.
-                  $values['postalCode'] .' '.
-                  $values['locality']['name'] .' '.
-                  $values['administrativeArea']['code'],
-      '@line7' => $country,
-    ]);
-    
-    return $expected;
-  }
-  /**
-   * Gets the subdivisions.
-   *
-   * @param \CommerceGuys\Addressing\Model\Address $address
-   *   The address.
-   *
-   * @return array
-   *   The values keyed by subdivision name.
-   */
-  protected function getSubdivisions(Address $address) {
-    $values = [];
-    foreach (AddressField::getAll() as $field) {
-      $getter = 'get' . ucfirst($field);
-      $values[$field] = $address->$getter();
-    }
 
-    // Replace the subdivision values with the names of any predefined ones.
-    $subdivisionFields = [
-      AddressField::ADMINISTRATIVE_AREA,
-      AddressField::LOCALITY,
-      AddressField::DEPENDENT_LOCALITY,
-    ];
-    foreach ($subdivisionFields as $field) {
-      if (empty($values[$field])) {
-        // This level is empty, so there can be no sublevels.
-        break;
-      }
-      $subdivision = $this->subdivisionRepository->get($values[$field], $address->getLocale());
-      if (!$subdivision) {
-        // This level has no predefined subdivisions, stop.
-        break;
-      }
-
-      $values[$field] = ['code' => $subdivision->getCode(), 'name' => $subdivision->getName()];
-      if (!$subdivision->hasChildren()) {
-        // The current subdivision has no children, stop.
-        break;
-      }
-    }
-
-    // If there was no corresponding objects found, load strings from $address.
-    foreach ($subdivisionFields as $field) {
-      $getter = 'get' . ucfirst($field);
-      if (!isset($values[$field]) || !is_array($values[$field])) {
-        $values[$field] = ['code' => '', 'name' => $address->$getter()];
-      }
-    }
-    return $values;
-  }
 }
-
diff --git a/templates/address-plain.html.twig b/templates/address-plain.html.twig
index e130097..e2b1079 100644
--- a/templates/address-plain.html.twig
+++ b/templates/address-plain.html.twig
@@ -32,5 +32,8 @@
 {{ address_line1 }}
 {{ address_line2 }}
 {{ dependent_locality.code }}
-{{ locality.code }} {{ postal_code }} {{ locality.name }} {{ administrative_area.code }}
+{{ locality.code }}
+{{ postal_code }}
+{{ locality.name }}
+{{ administrative_area.code }}
 {{ country.name }}
