'Showing the name of a polygon along the edge of that polygon

In the following picture there's a line and on one side of it it says "United States" and on the other side it says "Mexico". And both words are parallel to that line.

enter image description here

My question is... how can I achieve a similar effect with leafletjs?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source