Get interface translation LID (Locale Id?) using source string value I'm using User interface translation in English to override system strings like Drupal 7's String Overrides module did. Works great. However, in my custom module, as I edit strings that run through the t() function, the Source string table in User interface translation is filling up with unused strings.

I'm writing a simple function to delete unwanted source strings one-by-one. The post at http://www.drupal8.ovh/en/tutoriels/89/delete-a-source-string-and-target-translations-drupal-8 provides code for deleting a translation once you know the LID (Locale Id?), which it suggests you get by inspecting the HTML of the displayed User interface translation page.

Question: Is there a way to look up the LID for a source string using the text of the source string?

I've read many posts, but don't see any that suggest how to do this.
OK: Figured it out through trial and error. Here's the code:

$db = \Drupal::database();

$query = $db-&gt;select('locales_source', 'ls')-&gt;
    condition('source', $source_string)-&gt;
    fields('ls', ['lid'])-&gt;
    range(0, 1);

$lid = $query-&gt;execute()-&gt;fetchField();


UPDATE: Found a cleaner way. Here's the code:

$storage = \Drupal::service('locale.storage');
$string = $storage-&gt;findString(['source' =&gt; $source_string]);

if (!is_null($string)) {
  $lid = $string-&gt;lid;
}


I'm using this now in a custom module. Seems to be working well.