Localized ElementTypes in a plugin My question is re: localization of ElementTypes in a plugin.  I have the records all working fine in multiple locales.

The part that I'm not "getting" is I think there should be one Element in craft_elements and then for each localization, there should be one record in craft_elements_i18n yes?  And then for each localization, there should be a separate record in my craft_seomatic_meta table for each localized version yes?

This is where in my controller it saves the ElementType: https://github.com/khalwat/seomatic/blob/master/controllers/SeomaticController.php#L173

And here is the function is calls in my service to save the element &amp; record: https://github.com/khalwat/seomatic/blob/master/services/SeomaticService.php#L683

When I call $result = craft()-&gt;elements-&gt;getElementById($metaId, 'Seomatic_Meta', $locale); how does it "know" which record to look up to load the returned Seomatic_MetaElementType with data?

I'm clearly missing something basic regarding how this should all work
The part that I'm not "getting" is I think there should be one Element in craft_elements and then for each localization, there should be one record in craft_elements_i18n yes? 


Yes.


  And then for each localization, there should be a separate record in my craft_seomatic_meta table for each localized version yes?


Only if the values in that table need to be stored on a per-locale basis, which to my knowledge has never been the case until now with SEOmatic.


  When I call $result = craft()->elements->getElementById($metaId, 'Seomatic_Meta', $locale); how does it "know" which record to look up to load the returned Seomatic_MetaElementType with data?


Any time you run an element query (which getElementById() does), the element type’s modifyElementsQuery() method will be called, which gives the element type a chance to make changes to the query. In yours, you have the following code:

$query
    -&gt;addSelect('seomatic_meta.*')
    -&gt;join('seomatic_meta seomatic_meta', 'seomatic_meta.elementid = elements.id')
    -&gt;andWhere(DbHelper::parseParam('seomatic_meta.locale', $criteria-&gt;locale, $query-&gt;params));


That condition you’re adding to the query on the seomatic_meta.locale column is what is ensuring that the correct localized row in your seomatic_meta table will be included in the result.

That’s just for selecting elements though. I might be missing something, but looking at your SeomaticService::saveMeta() method, it doesn’t look like you’re ever ensuring that all of the localized rows are actually getting saved. If you take a look through ElementsService::saveElement(), you will see that one of the things it does is loop through the locales returned by $element-&gt;getLocales() and make sure that there’s an ElementLocaleRecord (elements_i18n row) for the element in each of those locales. If you want to store rows for each locale in your own craft_seomatic_meta table, it’s the plugin’s responsibility to do that, not Craft’s.